top | item 37158951

(no title)

palotasb | 2 years 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=s...

[2]: https://docs.python.org/3/library/stdtypes.html#boolean-valu...

discuss

order

tlocke|2 years ago

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