S
Steven D'Aprano
My point stands.
Your point is wrong. Ints and longs weren't unified because it is
"cryptonic" (cryptic?), but to avoid the user needing to care about the
difference between ints and longs. I've been coding in Python since
version 1.5, and I can tell you I hated the need to write code like this:
def make_int(obj):
try:
return int(obj)
except ValueError:
return long(int)
To say nothing of:
def add(x, y):
try:
return x+y
except OverflowError:
return long(x)+long(y)
Having the int class automatically promote instances to long as needed
was a HUGE win for simplicity and readability, while still saving memory
and performance for small ints.
Still not convinced that it's allowed to return objects of a different
type? From Python 3.1:
<range_iterator object at 0xb7cd8a88>reversedreversed((1,2,3))reversed("abcd")reversed([1,2,3])reversed(range(10))