5 ms·
For what it's worth, I tried a modified version of the first example you've used above in the sandbox: NOT_FOUND = 404 match get_status(): case NOT_F
by EwanToo 6y ago
For what it's worth, I tried a modified version of the first example you've used above in the sandbox:
NOT_FOUND = 404
match get_status():
case NOT_FOUND:
print("Here")
# this actually assigns to the global NOT_FOUND
# and is effectively the default case
case _:
# this never gets triggered
print("There")
I got a meaningful error:
File "<ipython-input-13-5264d8327114>", line 3
case NOT_FOUND:
^
SyntaxError: name capture 'NOT_FOUND' makes remaining patterns unreachable
- hyperbovine 6y agoThat in itself is weird though. Why throw a syntax error there but not here?: def f(x): return 1 y = x + 1 return y