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

Fix F821 false negatives when from __future__ import annotations is active (attempt 2) #10524

Merged
merged 1 commit into from Mar 22, 2024

Conversation

AlexWaygood
Copy link
Member

@AlexWaygood AlexWaygood commented Mar 22, 2024

A second attempt to fix #10340. The earlier attempt was #10362, which was reverted in #10513.

#10362 incorrectly only allowed forward references in annotations if we were in a "typing-only annotation". But forward references are allowed in all type annotations, not just typing-only annotations, iff from __future__ import annotations is at the top of the file.

Test plan

cargo test. The tests added in #10513 should prevent a repeat of the earlier regression that #10362 caused.

Copy link
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@AlexWaygood AlexWaygood merged commit b74dd42 into main Mar 22, 2024
17 checks passed
@AlexWaygood AlexWaygood deleted the f821-try-2 branch March 22, 2024 18:11
# More circular references
class Leaf: ...
class Tree(list[Tree | Leaf]): ... # Still invalid even when `__future__.annotations` are enabled
class Tree2(list["Tree | Leaf"]): ... # always okay
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't quite testing what was intended and ought to be:

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Luckily the corrected test still passes, however.

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

Successfully merging this pull request may close these issues.

F821: false negatives when a file has from __future__ import annotations
3 participants