-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
] Make PYI019
autofixable for .py
files in preview mode as well as stubs
#15889
Merged
Conversation
This file contains 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
.../flake8_pyi/snapshots/ruff_linter__rules__flake8_pyi__tests__preview_PYI019_PYI019_0.py.snap
Outdated
Show resolved
Hide resolved
|
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
PYI019 | 26 | 0 | 0 | 26 | 0 |
crates/ruff_linter/src/rules/flake8_pyi/rules/custom_type_var_for_self.rs
Outdated
Show resolved
Hide resolved
2b3ff8d
to
75cca5e
Compare
e82e76b
to
4e2dc61
Compare
8638557
to
5b47b63
Compare
4e2dc61
to
a73295b
Compare
ad034d2
to
e8320a0
Compare
a73295b
to
0e243a3
Compare
e8320a0
to
f75d7de
Compare
f75d7de
to
b5cf87c
Compare
MichaReiser
approved these changes
Feb 4, 2025
crates/ruff_linter/resources/test/fixtures/flake8_pyi/PYI019_0.py
Outdated
Show resolved
Hide resolved
…ode as well as stubs
b5cf87c
to
31e660b
Compare
dcreager
added a commit
that referenced
this pull request
Feb 4, 2025
* main: (66 commits) [red-knot] Use ternary decision diagrams (TDDs) for visibility constraints (#15861) [`pyupgrade`] Rename private type parameters in PEP 695 generics (`UP049`) (#15862) Simplify the `StringFlags` trait (#15944) [`flake8-pyi`] Make `PYI019` autofixable for `.py` files in preview mode as well as stubs (#15889) Docs (`linter.md`): clarify that Python files are always searched for in subdirectories (#15882) [`flake8-pyi`] Make PEP-695 functions with multiple type parameters fixable by PYI019 again (#15938) [red-knot] Use unambiguous invalid-syntax-construct for suppression comment test (#15933) Make `Binding::range()` point to the range of a type parameter's name, not the full type parameter (#15935) Update black deviations (#15928) [red-knot] MDTest: Fix line numbers in error messages (#15932) Preserve triple quotes and prefixes for strings (#15818) [red-knot] Hand-written MDTest parser (#15926) [`pylint`] Fix missing parens in unsafe fix for `unnecessary-dunder-call` (`PLC2801`) (#15762) nit: docs for ignore & select (#15883) [airflow] `BashOperator` has been moved to `airflow.providers.standard.operators.bash.BashOperator` (AIR302) (#15922) [`flake8-logging`] `.exception()` and `exc_info=` outside exception handlers (`LOG004`, `LOG014`) (#15799) [red-knot] Enforce specifying paths for mdtest code blocks in a separate preceding line (#15890) [red-knot] Internal refactoring of visibility constraints API (#15913) [red-knot] Implicit instance attributes (#15811) [`flake8-comprehensions`] Handle extraneous parentheses around list comprehension (`C403`) (#15877) ...
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.
(This PR is stacked on top of #15885 and #15888; review those first.)
Summary
Now that this is a bindings-based rule, I think the autofix can be safely applied to
.py
files as well as stubs. All we need to do is search the method body for references we might need to replace as well as searching the method header.@InSyncWithFoo mentioned in #15821 that there might be some edge cases to do with stringized type expressions where this wouldn't work well. I've made the rule unfixable in these edge cases by
bail
ing out of the fix if we see that any references in the source code do not exactly match the original TypeVar name.Test Plan
New snippets added to the fixture files.