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

F821 with Annotated import alias #789

Open
alanhdu opened this issue Oct 17, 2023 · 1 comment
Open

F821 with Annotated import alias #789

alanhdu opened this issue Oct 17, 2023 · 1 comment

Comments

@alanhdu
Copy link

alanhdu commented Oct 17, 2023

We have a use-case where we sometimes import Annotated under a different name (since there is a naming collision with an existing object callled Annotations and Annotated[Annotations, ...] can be hard to read. Unfortunately, it looks like if we try to do this, then we fail with a false positive:

from typing_extensions import Annotated as WithSchema


def f(x: WithSchema[int, "hello"]) -> None:
    return

fails pyflakes with F821 undefined name 'hello.

Everything works fine if we do not use the Annotated as WithSchema import alias though. Would it be possible to extend the logic to also handle such a case?

cc @nishkakar @ezrilow

@jayvdb
Copy link
Member

jayvdb commented Feb 14, 2024

Confirm the "as" syntax triggers this. Thanks for raising the issue.

If you want to find the problem, very likely it is somewhere in _is_typing_helper

It may not be taking into account alias.asname c.f. https://docs.python.org/3/library/ast.html#ast.alias

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