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