[Python-Dev] __index__ clipping
Guido van Rossum
guido at python.org
Wed Aug 9 23:46:09 CEST 2006
Here's another issue where Neal thought it would be useful if I
weighed in. I'm not quite sure of the current status, but perhaps the
following would work?
- Called from Python, (10**10).__index__() should return 10000000000L,
not raise an exception or return sys.maxint.
- The nb_index slot is changed to return an object; it should return a
Python int or long without clipping (same as __index__() called from
- There should be three C APIs (perhaps fewer if some of them are never needed):
- One to call the nb_index slot, or raise an exception if it's not
set, returning the object
- One to return the clipped value without an exception
(can still return an exception if something else went wrong)
- One to return the value if it fits, raise OverflowError if it doesn't
I know this is quite the deviation from the current code but it seems
the most rational and future-proof approach.
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-Dev