[ruff] Add fix for none-not-at-end-of-union (RUF036) #22829
[ruff] Add fix for none-not-at-end-of-union (RUF036) #22829amyreese merged 12 commits intoastral-sh:mainfrom
ruff] Add fix for none-not-at-end-of-union (RUF036) #22829Conversation
ruff] Add fix for none-not-at-end-of-union (RUF036) none-not-at-end-of-union (RUF036)
crates/ruff_linter/src/rules/ruff/rules/none_not_at_end_of_union.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/ruff/rules/none_not_at_end_of_union.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/ruff/rules/none_not_at_end_of_union.rs
Outdated
Show resolved
Hide resolved
|
@amyreese Thanks for the review! I've addressed all the feedback:
Ready for another look whenever you have a chance. Thank you! |
|
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| RUF036 | 790 | 395 | 395 | 0 | 0 |
|
Thanks @anishgirianish for working on this! I haven't looked at the diff yet, so apologies if you've addressed all of these, but I was hoping you could check whether or not you had resolved my comment on a previous version of this PR? See #18964 (review) and the comments it links to on an even earlier version. I think that's a good summary of the missing pieces from the earlier iterations and would help me get started reviewing this PR. |
Sure will do thanks |
crates/ruff_linter/src/rules/ruff/rules/none_not_at_end_of_union.rs
Outdated
Show resolved
Hide resolved
|
LGTM, unless @ntBre knows of any relevant helpers that could be reused. |
.../ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__RUF036_RUF036.py.snap
Outdated
Show resolved
Hide resolved
Thank you for the review! I've skipped the fix for PEP 604 unions with multiple Nones to avoid generating None | None. Ready for another look whenever you get a chance! |
ntBre
left a comment
There was a problem hiding this comment.
Looks good to me! I'll leave it to Amy to merge.
crates/ruff_linter/src/rules/ruff/rules/none_not_at_end_of_union.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/ruff/rules/none_not_at_end_of_union.rs
Outdated
Show resolved
Hide resolved
none-not-at-end-of-union (RUF036) ruff] Add fix for none-not-at-end-of-union (RUF036)
|
@amyreese thank you for the latest commit. I really appreciate it |
* main: [ty] Take myself out of the reviewer pool for the next few days (#23618) [ty] Fix bug where ty would think that a `Callable` with a variadic positional parameter could be a subtype of a `Callable` with a positional-or-keyword parameter (#23610) [`ruff`] Add fix for `none-not-at-end-of-union` (`RUF036`) (#22829) Bump cargo dist to 0.31 (#23614) [`pyflakes`] Fix false positive for names shadowing re-exports (`F811`) (#23356) [`fastapi`] Handle callable class dependencies with `__call__` method (`FAST003`) (#23553) [ty] Recurse into tuples and nested tuples when applying special-cased validation of `isinstance()` and `issubclass()` (#23607) Update typing conformance suite commit (#23606) [ty] Detect invalid uses of `@final` on non-methods (#23604) [ty] Move the type hierarchy request handlers to individual modules [ty] Wire up the type hierarchy implementation with the LSP [ty] Add routine for mapping from system path to vendored path [ty] Implement internal routines for providing the LSP "type hierarchy" feature [ty] Add some helper methods on `ClassLiteral` [ty] Move some module name helper routines to methods on `ModuleName` [ty] Bump version of `lsp-types` [ty] Refactor to support building constraint sets differently (#23600) [ty] Dataclass transform: neither frozen nor non-frozen (#23366) [ty] Add snapshot tests for advanced `invalid-assignment` scenarios (#23581) [ty] disallow negative narrowing on SubclassOf types (#23598)
Summary
Adds an autofix for
RUF036that movesNoneto the end of union type annotations.Closes #15136
The fix:
|vstyping.Union)Nonevalues instead of deduplicatingNone | Union[int, str])Test Plan
cargo nextest run -p ruff_linter- added test cases for nested unions, comments,default arguments, and mixed styles.