Trying to learn Python 3.10 pattern matching. Tried this example after reading 8.6.4.9. Mapping Patterns
>>> match 0.0:
... case int(0|1):
... print(1)
...
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
TypeError: called match pattern must be a type
>>>
Especially the note on built-in types, including int. How should I code to test for an integer value of 0 or 1 (the example in the doc) and not get this error?
I fell into a gotcha:
match 0.0
case int:
print(1)
effectively redefines int, so the next time I tried the match I posted, it failed since my int was shadowing the built in
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With