[flake8-pyi] Teach various rules that annotations might be stringized#12951
Merged
AlexWaygood merged 1 commit intomainfrom Sep 2, 2024
Merged
[flake8-pyi] Teach various rules that annotations might be stringized#12951AlexWaygood merged 1 commit intomainfrom
flake8-pyi] Teach various rules that annotations might be stringized#12951AlexWaygood merged 1 commit intomainfrom
Conversation
5bf9327 to
e006312
Compare
Contributor
|
| 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
MichaReiser
reviewed
Aug 19, 2024
Member
MichaReiser
left a comment
There was a problem hiding this comment.
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
charliermarsh
approved these changes
Aug 29, 2024
Member
charliermarsh
left a comment
There was a problem hiding this comment.
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.)
This was referenced Aug 29, 2024
Member
Author
I separated this out into a standalone PR: #13158 |
MichaReiser
approved these changes
Sep 2, 2024
87a0c9c to
8c2653c
Compare
Centralize the parsing of string annotations in a method on `Checker`
8c2653c to
bdc1c2e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #12928.
Most
flake8-pyirules 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-pyirules to reduce false positives and false negatives on stringized annotations.I haven't attempted to exhaustively account for stringized annotations in every
flake8-pyirule. In some rules, this would have significantly complicated the logic, for marginal gain.Test Plan
Several new fixtures and snapshots added.