[Python-Dev] [Python-checkins] r87445 - python/branches/py3k/Lib/numbers.py

Éric Araujo merwok at netwok.org
Sun Dec 26 18:13:53 CET 2010

Le 24/12/2010 02:08, Nick Coghlan a écrit :
> On Fri, Dec 24, 2010 at 4:41 AM, eric.araujo <python-checkins at python.org> wrote:
>> Fix small inaccuracy: there is no index function
> Yes, there is, it just isn't a builtin - it lives in the operator module.
Defining object.__index__ with operator.index seems pretty circular to
me :)  http://docs.python.org/dev/reference/datamodel#object.__index__
does it, but it should be fixed IMO.  The difference between __int__ and
__index__ is also not clear.

>>     def __index__(self):
>> -        """index(self)"""
>> +        """someobject[self]"""
>>         return int(self)
> Changing the docstring to say "operator.index(self)" would be the
> clearest solution here.
I disagree.  __add__ is documented as implementing +, not operator.add.

> (Choosing to accept arbitrary index objects as
> integer equivalents is up to the object being indexed, just like
> interpreting slices is - a dict, for example, will never invoke
> __index__ methods).
I honestly don’t know what the best fix is.  We could copy the doc from
datamodel (“called whenever Python needs an integer object (such as in
slicing, or in the built-in bin(), hex() and oct() functions)”).  I’ve
been told on IRC to let Mark Dickison decide how to fix the docstrings
in the numbers module (deleting them being of course an option: magic
methods are documented in the language reference, they don’t need


More information about the Python-Dev mailing list