6 ms·
bool is explicitly documented to be a subclass of int [1][2], so while it might be an obscure feature, or subjectively not someone's preferred style, I don't se
by palotasb 3y ago
bool is explicitly documented to be a subclass of int [1][2], so while it might be an obscure feature, or subjectively not someone's preferred style, I don't see any typing related issue. In general I don't think that treating an object as if it were an instance of one of its base classes is weak typing.
[1]: https://docs.python.org/3/library/functions.html?highlight=subclass#bool https://docs.python.org/3/library/functions.html?highlight=s...
[2]: https://docs.python.org/3/library/stdtypes.html#boolean-values https://docs.python.org/3/library/stdtypes.html#boolean-valu...
- tlocke 3y agoI'd argue that even though it's well defined behaviour in Python, it still appears to me as a programmer as weak typing. For example, Python lets me write: if 23: print('hello') and it'll print 'hello'. But I'd prefer a strongly typed approach where this code would give an error saying, 'a bool is expected here'. Sure it's a subjective thing, and this is just my preference.