Skip to content

refactor: use match-case for dispatch chains - #926

Merged
pvital merged 1 commit into
mainfrom
match-case-improvement
Dec 4, 2026
Merged

pvital merged 1 commit into
mainfrom
match-case-improvement

Conversation

@pvital

@pvital pvital commented Dec 3, 2026

Copy link
Copy Markdown
Member

Python implements the case statement via the match and case keywords, introduced in Python 3.10 as part of structural pattern matching (PEP 634). This feature allows an expression to be compared against successive patterns, executing the code block associated with the first match found.

This PR replaces if/elif chains that dispatch on a single subject with structural pattern matching (PEP 634) in secrets, registered spans, span exception recording, and the FastAPI, Starlette, and Django middleware instrumentation. It also converts the equivalent chains in the related tests.

Replace if/elif chains that dispatch on a single subject with structural pattern matching (PEP 634) in secrets, registered spans, span exception recording, and the FastAPI, Starlette and Django middleware instrumentation. Convert the equivalent chains in the related tests. Branch order and behavior are unchanged.

Signed-off-by: Paulo Vital <paulo.vital@ibm.com>
@pvital pvital self-assigned this Dec 3, 2026
@pvital
pvital requested a review from a team as a code owner December 3, 2026 09:58
@pvital pvital added the refactor label Dec 3, 2026

@arjun-rajappa arjun-rajappa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@CagriYonca CagriYonca left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

@pvital
pvital merged commit 4c9c02a into main Dec 4, 2026
25 of 26 checks passed
@pvital
pvital deleted the match-case-improvement branch December 4, 2026 05:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants