Respect duplicates when rewriting type aliases#9905
Merged
charliermarsh merged 1 commit intomainfrom Feb 9, 2024
Merged
Conversation
Contributor
|
AlexWaygood
approved these changes
Feb 9, 2024
| x: TypeAlias | ||
| x: int = 1 | ||
|
|
||
| # UP040 won't raise if a generic is repeated. |
Member
There was a problem hiding this comment.
It looks like we are actually emitting a violation here, right? (And I think that's correct!)
Suggested change
| # UP040 won't raise if a generic is repeated. | |
| # Make sure "T" appears only once | |
| # in the type parameters for the modernized type alias |
| let vars = vars | ||
| .into_iter() | ||
| .unique_by(|TypeVar { name, .. }| name.id.as_str()) | ||
| .collect::<Vec<_>>(); |
Member
There was a problem hiding this comment.
Since Itertools is already in scope, you could avoid the turbofish here:
Suggested change
| .collect::<Vec<_>>(); | |
| .collect_vec(); |
Member
Author
There was a problem hiding this comment.
As a habit, I try to avoid using Itertools where it's not providing much value since it (1) makes it a little easier if we remove the dep in the future and (2) in my opinion at least it's actually easier to read the explicit version.
420d5e0 to
65fc440
Compare
nkxxll
pushed a commit
to nkxxll/ruff
that referenced
this pull request
Mar 10, 2024
## Summary If a generic appears multiple times on the right-hand side, we should only include it once on the left-hand side when rewriting. Closes astral-sh#9904.
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
If a generic appears multiple times on the right-hand side, we should only include it once on the left-hand side when rewriting.
Closes #9904.