Skip to content

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

henryiii
Copy link
Contributor

Adding some pattern matching where I think it makes sense to do so.

henryiii added 2 commits May 29, 2025 13:25
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
@henryiii henryiii requested a review from Copilot May 29, 2025 22:05
Copilot

This comment was marked as outdated.

@joerick
Copy link
Contributor

joerick commented May 29, 2025

Do you mind if we punt this to after v3.0? Big diffs like this seem like unecessary risk when tapering to a release.

@henryiii henryiii added the Hold for future release This PR might be complete, but is scheduled to be merged in a future release. Don't merge yet. label May 29, 2025
@henryiii
Copy link
Contributor Author

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])):
Copy link
Contributor Author

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. :)

@joerick joerick removed the Hold for future release This PR might be complete, but is scheduled to be merged in a future release. Don't merge yet. label Jun 11, 2025
@henryiii henryiii requested a review from Copilot June 19, 2025 16:22
Copy link

@Copilot Copilot AI left a 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 converts several conditional chains to Python's pattern matching syntax to streamline the code.

  • Refactored AST checking in projectfiles.py
  • Replaced if/elif chains with match-case in platforms modules (windows, macos, linux, ios) and oci_container.py
  • Applied pattern matching for merging rules and settings conversion in options.py

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
cibuildwheel/projectfiles.py Converted AST conditionals to a match-case construct for evaluating if a node is the main check.
cibuildwheel/platforms/windows.py Replaced string comparisons with match-case on build frontend values.
cibuildwheel/platforms/macos.py Updated build and setup routines to use pattern matching consistently.
cibuildwheel/platforms/linux.py Simplified build_in_container logic with match-case on build frontend names.
cibuildwheel/platforms/ios.py Enhanced build and setup logic by using pattern matching for cleaner control flow.
cibuildwheel/options.py Switched to match-case for merging options and stringifying settings, although a potential issue exists.
cibuildwheel/oci_container.py Replaced if-elif comparisons with a match-case structure for engine version validation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants