-
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
Respect duplicates when rewriting type aliases #9905
Conversation
|
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.
LGTM
@@ -46,3 +46,7 @@ class Foo: | |||
# OK | |||
x: TypeAlias | |||
x: int = 1 | |||
|
|||
# UP040 won't raise if a generic is repeated. |
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.
It looks like we are actually emitting a violation here, right? (And I think that's correct!)
# UP040 won't raise if a generic is repeated. | |
# Make sure "T" appears only once | |
# in the type parameters for the modernized type alias |
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.
Yes, thank you!
let vars = vars | ||
.into_iter() | ||
.unique_by(|TypeVar { name, .. }| name.id.as_str()) | ||
.collect::<Vec<_>>(); |
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.
Since Itertools
is already in scope, you could avoid the turbofish here:
.collect::<Vec<_>>(); | |
.collect_vec(); |
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.
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
## 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.
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.