3 ms·
Python accepts: 1 + True == False + 2 It should have to be: 1 + int(True) == int(False) + 2
by cma 14y ago
Python accepts:
1 + True == False + 2
It should have to be:
1 + int(True) == int(False) + 2
- ubernostrum 14y agoPython accepts this because bool is a subclass of int, and True and False have defined integer values (1 and 0 respectively). Which means there's no coercion or conversion going on here. For what you think it "should" be, Python would have to break Liskov substitution for subclasses of int.
- cma 14y agoIt shouldn't be a subclass of int. http://arxiv.org/abs/math/9205211 http://arxiv.org/abs/math/9205211
- pekk 14y agoThen it gets fixed, and everyone screams because it's not backward compatible (Python 3).
- cma 14y agoIt should have just been part of Python 3.
- mixmastamyk 14y agoYep, but they didn't aim to or succeed in 'fixing everything' in python3, just the most pressing items. Here's to Python 4!
- ubernostrum 14y agoYou're free to argue that. But the fact that it is, and behaves correctly as a subclass of int, does not make Python be weakly typed. In fact, rather the opposite.