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: false negatives when a file has from __future__ import annotations #10340

Closed
AlexWaygood opened this issue Mar 11, 2024 · 1 comment · Fixed by #10362 or #10524
Closed

F821: false negatives when a file has from __future__ import annotations #10340

AlexWaygood opened this issue Mar 11, 2024 · 1 comment · Fixed by #10362 or #10524
Assignees
Labels
bug Something isn't working linter Related to the linter

Comments

@AlexWaygood
Copy link
Member

AlexWaygood commented Mar 11, 2024

Ruff currently emits no F821 errors on this .py file, but the lines marked with XXX all fail at runtime due to undefined names:

from __future__ import annotations

from typing import TypeAlias, Optional, Union

MaybeCStr: TypeAlias = Optional[CStr]  # XXX
MaybeCStr2: TypeAlias = Optional["CStr"]  # always okay
CStr: TypeAlias = Union[C, str]  # XXX
CStr2: TypeAlias = Union["C", str]  # always okay

class C: ...

class Leaf: ...
class Tree(list[Tree | Leaf]): ...  # XXX
class Tree2(list["Tree | Leaf"]): ...  # always okay

Note:

  • Ruff correctly emits three errors on this file when from __future__ import annotations is not included
  • Ruff correctly emits no errors on this file if it's a .pyi stub file.
@AlexWaygood
Copy link
Member Author

The PR fixing this was reverted in #10513

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working linter Related to the linter
Projects
None yet
2 participants