-
Notifications
You must be signed in to change notification settings - Fork 179
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
Circular dependencies in Python < 3.7 string annotations #453
Comments
I cannot reproduce on master or on pyflakes 2.1.1 $ ~/opt/venv/bin/pyflakes --version
2.1.1 Python 3.6.8 on Linux
$ ~/opt/venv/bin/pyflakes t.py
$ echo $?
0 $ python3.6 -m pyflakes t.py
$ echo $?
0 |
Apologies, I should have tested my snippet - it turns out I oversimplified my real use case. from typing import Union, TYPE_CHECKING
if TYPE_CHECKING:
# Circular dependency; module_b imports this module in its header
from module_b import SomeClass
def f() -> Union["SomeClass", int]:
from module_b import SomeClass
return SomeClass(1, 2, 3) pyflakes output:
Please reopen |
Interestingly, this triggers the issue: def f() -> Union["SomeClass", int]: but this doesn't: def f() -> "Union[SomeClass, int]": and, as said in the op, this doesn't either (but requires py37): from __future__ import annotations
def f() -> Union[SomeClass, int]: |
that's a dupe of #447 -- the workaround for now being to quote the entire annotation or use |
@crusaderky would you like to review the solution in #479 to see if it fixes your problem for you? |
@asottile confirmed it solves the issue |
@crusaderky would you be able to code review the patch? |
@asottile |
When a function of module A needs to use and return an object of module B, but module B already imports module A, you will typically see this pattern in Python >=3.5.2, <3.7:
pyflakes 2.1.1 produces errors when parsing this file:
Notably, pyflakes does not complain when the same is rewritten using delayed annotation, which however requires Python 3.7:
The text was updated successfully, but these errors were encountered: