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

Handle forward references consistently (PyInf#11514) #275

Open
dshivashankar1994 opened this issue Nov 27, 2023 · 1 comment
Open

Handle forward references consistently (PyInf#11514) #275

dshivashankar1994 opened this issue Nov 27, 2023 · 1 comment

Comments

@dshivashankar1994
Copy link
Collaborator

tidy-imports seems to complain about every other type annotation that uses a forward reference:

$ tidy-imports --diff <<END
from __future__ import annotations

def f1(x: X) -> None:
    pass

def f2(x: X) -> None:
    pass

def f3(x: X) -> None:
    pass

def f4(x: X) -> None:
    pass

class X:
    pass
END

[PYFLYBY] /dev/stdin:6: undefined name 'X' and no known import for it
[PYFLYBY] /dev/stdin:12: undefined name 'X' and no known import for it

Strictly speaking, if the annotations future feature is being used then the annotations can contain arbitrary values, since Python won't try to evaluate them, but in practice it's probably fine to assume that they are being used as type annotations and can be evaluated.

Forward references without using the annotations future feature work:

$ tidy-imports --diff <<END
def f1(x: "X") -> None:
    pass

def f2(x: "X") -> None:
    pass

def f3(x: "X") -> None:
    pass

def f4(x: "X") -> None:
    pass

class X:
    pass
END
@Carreau
Copy link
Collaborator

Carreau commented Jan 17, 2024

I think this is a deeper problem with Pyflyby, as the codebase is designed to do depth first search in a single pass there is always scoping issues, and every time we have a problem with this we add a band aid and special casing.

IMHO it will be hard to consistency fix those without a major rewrite, and having those checks be done in multiple passes to properly apply python scoping rules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants