[Python-Dev] "result type only depends on operand types"...?

Alex Martelli aleax@aleax.it
Sun, 31 Mar 2002 18:38:58 +0100


Back on March 10 in the thread on PEP 285 Guido wrote:

"""
This is a very general rule that I like a lot: that the type of a
result should only depend on the type of the arguments, not on their
values.  I expect that this rule will make reasoning about programs
(as in PsyCo or PyChecker) easier to do.

I recently caved in and allowed an exception: 2**2 returns an int, but
2**-2 returns a float.  This was a case of "practicality beats
purity".  I don't see True-1 in the same league though.
"""

And yet...:

>>> type(2**10)
<type 'int'>
>>> type(2**100)
<type 'long'>

...doesn't this apply to many operators on ints in 2.2?  Yet _another_
(set of) exception(s) with practicality beating purity?  Perhaps, but if a 
"very general rule" has so many exceptions in frequent and fundamental
cases, is it a rule at all...?


Alex