3 ms·
Just to elaborate, it short circuits, so x need not be defined. [sielicki@dogfruit ~]$ python3.10 -c 'print(0xf or some_undefined_variable in some_undefine
by nickysielicki 6y ago
Just to elaborate, it short circuits, so x need not be defined.
[sielicki@dogfruit ~]$ python3.10 -c 'print(0xf or some_undefined_variable in some_undefined_set)'
15
- wyldfire 6y agoThis is the kinda thing that helps illustrate just how powerfully dynamic Python is. Almost nothing is statically bound. Super cool if you want to write code that inspects some dynamic state and has special behavior. But the cost is that there's very little static checking capability. This code "should" result in a NameError or something similar. But resolving that identifier to a name won't happen until we decide to evaluate the right-hand side of the `or`. Thankfully, most python static checkers make some mostly-sane assumptions and will flag this code as an error, despite the subtle possibility of legally creating this name using some other Python/CPython features. Type annotations are a great idea but in practice I don't see them used much. Should be great for dev teams working on bigger Python projects.