Skip to content

Commit

Permalink
Merge pull request #3868 from luigibertaco/from_future_annotations_as
Browse files Browse the repository at this point in the history
bugfix: accepts aliases for __future__ annotations
  • Loading branch information
hippo91 committed Oct 10, 2020
2 parents 83bc759 + badc425 commit 1a1dea5
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CONTRIBUTORS.txt
Expand Up @@ -412,6 +412,8 @@ contributors:

* David Cain: contributor

* Luigi Bertaco Cristofolini (luigibertaco): contributor

* Or Bahari

* Joshua Cannon: contributor
4 changes: 4 additions & 0 deletions ChangeLog
Expand Up @@ -38,6 +38,10 @@ Release date: TBA

* Fix AttributeError in checkers/refactoring.py

* Fix a bug with postponed evaluation when using aliases for annotations.

Close #3798

* Fix minor documentation issues

What's New in Pylint 2.6.0?
Expand Down
8 changes: 1 addition & 7 deletions pylint/checkers/utils.py
Expand Up @@ -1262,14 +1262,8 @@ def get_node_last_lineno(node: astroid.node_classes.NodeNG) -> int:

def is_postponed_evaluation_enabled(node: astroid.node_classes.NodeNG) -> bool:
"""Check if the postponed evaluation of annotations is enabled"""
name = "annotations"
module = node.root()
stmt = module.locals.get(name)
return (
stmt
and isinstance(stmt[0], astroid.ImportFrom)
and stmt[0].modname == "__future__"
)
return "annotations" in module.future_imports


def is_subclass_of(child: astroid.ClassDef, parent: astroid.ClassDef) -> bool:
Expand Down
28 changes: 28 additions & 0 deletions tests/functional/p/postponed_evaluation_activated_with_alias.py
@@ -0,0 +1,28 @@
# pylint: disable=missing-docstring,no-self-use,unused-argument,pointless-statement
# pylint: disable=too-few-public-methods,no-name-in-module
from __future__ import annotations as __annotations__


class MyClass:
@classmethod
def from_string(cls, source) -> MyClass:
...

def validate_b(self, obj: OtherClass) -> bool:
...


class OtherClass:
...


class Example:
obj: Other


class Other:
...


class ExampleSelf:
next: ExampleSelf
@@ -0,0 +1,2 @@
[testoptions]
min_pyver=3.7

0 comments on commit 1a1dea5

Please sign in to comment.