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, F822: fix false positive for .pyi files; add more test coverage for .pyi files #10341

Merged
merged 1 commit into from Mar 11, 2024

Conversation

AlexWaygood
Copy link
Member

@AlexWaygood AlexWaygood commented Mar 11, 2024

Summary

This PR fixes the following false positive in a .pyi stub file:

x: int
y = x  # F821 currently emitted here, but shouldn't be in a stub file

In a .py file, this is invalid regardless of whether from __future__ import annotations is enabled or not. In a .pyi stub file, however, it's always valid, as an annotation counts as a binding in a stub file even if no value is assigned to the variable.

I also added more test coverage for .pyi stub files in various edge cases where ruff's behaviour is currently correct, but where .pyi stub files do slightly different things to .py files. In the process of doing this, I discovered #10340.

Test Plan

cargo test

@AlexWaygood AlexWaygood added the bug Something isn't working label Mar 11, 2024
Copy link

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@AlexWaygood
Copy link
Member Author

✅ ecosystem check detected no linter changes.

Unfortunately typeshed already has F821 switched off in its config file due to this bug, or we'd likely see some changes here

@AlexWaygood AlexWaygood merged commit 4b06669 into astral-sh:main Mar 11, 2024
17 checks passed
@AlexWaygood AlexWaygood deleted the pyi-annassign-bindings branch March 11, 2024 22:15
charliermarsh added a commit that referenced this pull request Mar 21, 2024
## Summary

In #10341, we fixed some false
positives in `.pyi` files, but introduced others. This PR effectively
reverts the change in #10341 and fixes it in a slightly different way.
Instead of changing the _bindings_ we generate in the semantic model in
`.pyi` files, we instead change how we _resolve_ them.

Closes #10509.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants