Skip to content
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

Structural Pattern Matching Regular Expression WTF #298

Open
wyuenho opened this issue Sep 1, 2022 · 0 comments
Open

Structural Pattern Matching Regular Expression WTF #298

wyuenho opened this issue Sep 1, 2022 · 0 comments

Comments

@wyuenho
Copy link

wyuenho commented Sep 1, 2022

import re
DIGIT = re.compile(r"\d")

match "1":
    case DIGIT as i:
        print(i) # >>> 1

DIGIT # >>> '1' WTF!?

The reason is DIGIT is treated as a capture pattern, and the variable is thus reassigned in the case clause. DIGIT is assigned to "1" first, and then another variable i was created and the value of DIGIT, which now holds "1", is assigned to it.

PEP 634 does not define regular expression as a valid pattern.

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

No branches or pull requests

1 participant