-
Notifications
You must be signed in to change notification settings - Fork 264
chore: pattern matching #2434
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
base: main
Are you sure you want to change the base?
chore: pattern matching #2434
Conversation
Signed-off-by: Henry Schreiner <[email protected]>
Signed-off-by: Henry Schreiner <[email protected]>
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.
Pull Request Overview
This PR updates multiple modules to use Python’s structural pattern matching, replacing traditional if–elif chains for increased clarity and exhaustiveness. Key changes include refactoring conditionals in functions like is_main, setup_python, build, and others to use match/case and assert_never for default cases.
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
cibuildwheel/projectfiles.py | Replaced nested if conditions in is_main with a match/case statement supporting pattern matching. |
cibuildwheel/platforms/windows.py | Refactored build setup functions to employ match/case on build_frontend and its name. |
cibuildwheel/platforms/macos.py | Updated if–elif chains for build setup to use match/case patterns consistently. |
cibuildwheel/platforms/linux.py | Applied pattern matching to build_in_container logic instead of if–elif branches. |
cibuildwheel/platforms/ios.py | Converted if–elif conditions into match/case expressions for both setup_python and build functions. |
cibuildwheel/options.py | Implemented match/case for inheritance rules and setting type stringification. |
cibuildwheel/oci_container.py | Replaced if–elif conditions with match/case for engine.name in the version check functions. |
cibuildwheel/architecture.py | Used a match/case expression to selectively handle bitness values with assert_never as default. |
Do you mind if we punt this to after v3.0? Big diffs like this seem like unecessary risk when tapering to a release. |
Sure, I even almost added the tag when I opened it. |
|
||
return len(consts) == 1 | ||
match parent: | ||
case ast.If(test=ast.Compare(left=left, ops=[ast.Eq()], comparators=[comp])): |
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.
BTW, I really like this one too. :) I used AI to help me rewrite it - I'd generally think models do better on old code, but it knew exactly how to do this. :)
Adding some pattern matching where I think it makes sense to do so.