-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[flake8-pyi
] Teach various rules that annotations might be stringized
#12951
Conversation
5bf9327
to
e006312
Compare
|
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
PYI032 | 1 | 1 | 0 | 0 | 0 |
Linter (preview)
ℹ️ ecosystem check detected linter changes. (+1 -0 violations, +0 -0 fixes in 1 projects; 53 projects unchanged)
freedomofpress/securedrop (+1 -0 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview
+ securedrop/models.py:330:29: PYI032 [*] Prefer `object` to `Any` for the second parameter to `__eq__`
Changes by rule (1 rules affected)
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
PYI032 | 1 | 1 | 0 | 0 | 0 |
e006312
to
fdde658
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I leave the final review to @charliermarsh who's more familiar with that aspect of ruff
crates/ruff_linter/src/rules/flake8_pyi/rules/any_eq_ne_annotation.rs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good though I have roughly the same concern as Micha. Caching this would make sense to me. (We already parse these once per file anyway.)
I separated this out into a standalone PR: #13158 |
87a0c9c
to
8c2653c
Compare
Centralize the parsing of string annotations in a method on `Checker`
8c2653c
to
bdc1c2e
Compare
Summary
Fixes #12928.
Most
flake8-pyi
rules don't currently consider the possibility that annotations can be stringized --foo: "typing.Any"
means the same thing to a type checker asfoo: typing.Any
. This PR adds a general-purpose helper toruff_linter/src/rules/flake8_pyi/rules/helpers.rs
, and uses it in severalflake8-pyi
rules to reduce false positives and false negatives on stringized annotations.I haven't attempted to exhaustively account for stringized annotations in every
flake8-pyi
rule. In some rules, this would have significantly complicated the logic, for marginal gain.Test Plan
Several new fixtures and snapshots added.