Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

from __future__ import annotations as <identifier> not supported #3798

Closed
analog-cbarber opened this issue Aug 26, 2020 · 2 comments · Fixed by #3868
Closed

from __future__ import annotations as <identifier> not supported #3798

analog-cbarber opened this issue Aug 26, 2020 · 2 comments · Fixed by #3868
Labels
Bug 🪲 Good first issue Friendly and approachable by new contributors

Comments

@analog-cbarber
Copy link

In pylint 2.6.0 (and earlier) under python 3.7, the following produces an incorrect warning for
the '-> C:' return value.

from __future__ import annotations as __annotations__

class C:
    @classmethod
    def create(cls) -> C: # bogus warning: Undefined variable 'C'
        return cls()

There is no warning when the as clause is not there.

This clause is required in some spaces in order to avoid having the annotations symbol pollute the
namespace and is not supposed to affect the processing future clause.

See https://docs.python.org/3/reference/simple_stmts.html#future

@analog-cbarber
Copy link
Author

The problem appears to be here:
https://github.com/PyCQA/pylint/blob/5071831a5feb608fae1a4891ccec776860d3cce4/pylint/checkers/utils.py#L1266-L1275

This check is incorrect. I think that instead it should be checking the future_imports attribute
of the astroid Module object. I think this might work:

def is_postponed_evaluation_enabled(node: astroid.node_classes.NodeNG) -> bool: 
     """Check if the postponed evaluation of annotations is enabled""" 
     module = node.root()
     return "annotations" in module.future_imports

@AWhetter AWhetter added Bug 🪲 Good first issue Friendly and approachable by new contributors labels Sep 7, 2020
@AWhetter
Copy link
Contributor

AWhetter commented Sep 7, 2020

I can reproduce this on master with Python 3.8 as well. Your proposed correction looks like the right fix to me too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 Good first issue Friendly and approachable by new contributors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants