-
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
[pyupgrade
] Expand UP040 to handle generic functions and classes (UP040
, UP046
)
#15565
Open
ntBre
wants to merge
18
commits into
main
Choose a base branch
from
brent/pep695-generics
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+650
−124
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
and then TypeVarTuple and ParamSpec just works for functions too
This reverts commit 7a8cd3d.
|
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
This PR extends our PEP 695 handling from the type aliases handled by
UP040
to generic function and class parameters, as suggested in the latter two examples from #4617:I first implemented this as part of
UP040
, but based on a brief discussion during a very helpful pairing session with @AlexWaygood, I opted to split them into separate rules in the last 5 commits. From a quick look, and based on this issue, I'm pretty sure neither of these rules is currently in pyupgrade, so I just took the next available code,UP046
.The last main TODO, noted in the rule file and in the fixture, is to handle generic method parameters not included in the class itself,
S
in this case:but Alex mentioned that that might be okay to leave for a follow-up PR.
I also left a TODO about handling multiple subclasses instead of bailing out when more than one is present. I'm not sure how common that would be, but I can still handle it here, or follow up on that too.
I think this is unrelated to the PR, but when I ran
cargo dev generate-all
, it removed the rule codePLW0101
fromruff.schema.json
. It seemed unrelated, so I left that out, but I wanted to mention it just in case.Test Plan
New test fixture,
cargo nextest run