[Python-Dev] Please comment on PEP 357 -- adding nb_index slot to PyNumberMethods

Travis Oliphant oliphant.travis at ieee.org
Sat Feb 18 00:38:16 CET 2006


Thomas Wouters wrote:
> On Fri, Feb 17, 2006 at 05:29:32PM +0100, Armin Rigo wrote:
> 
>>>       Where obj must be either an int or a long or another object that has the
>>>       __index__ special method (but not self).
> 
> 
>>The "anything but not self" rule is not consistent with any other
>>special method's behavior.  IMHO we should just do the same as
>>__nonzero__():

Agreed.  I implemented the code, then realized this possible recursion 
problem while writing the specification.  I didn't know how it would be 
viewed.

It is easy enough to require __index__ to return an actual Python 
integer because for anything that has the nb_index slot you would just 
return obj.__index__()  instead of obj.

I'll change the PEP and the implementation.  I have an updated 
implementation that uses the ssize_t patch instead.

There seem to be some issues with the ssize_t patch still, though.

Shouldn't a lot of checks for INT_MAX be replaced with PY_SSIZE_T_MAX. 
But, I noticed that PY_SSIZE_T_MAX definition in pyport.h raises errors.
I don't think it even makes sense.

-Travis



More information about the Python-Dev mailing list