Re: [Python-Dev] r87445 - python/branches/py3k/Lib/numbers.py
On Thu, 23 Dec 2010 19:41:33 +0100 (CET) eric.araujo <python-checkins@python.org> wrote:
def __index__(self): - """index(self)""" + """someobject[self]"""
This is misleading as to what the method actually does, as you can read in the implementation:
return int(self)
Le 23/12/2010 20:55, Antoine Pitrou a écrit :
def __index__(self): - """index(self)""" + """someobject[self]"""
This is misleading as to what the method actually does, Really? Unless I misunderstood the docs, __index__ is used when the object is used as an index (or with bin or oct, but I didn’t want to complicate the docstring, just fix it).
On IRC, R. David Murray said that I could just have deleted the docstring. I agree with that: I think magic methods never need a docstring, since they’re documented once and for all in the language reference. (__init__ is not an exception: its parameters can be documented in the class docstring.)
as you can read in the implementation:
return int(self)
The fact that __index__ is implemented thanks to int/__int__ here is a detail IMO.
Regards
On Thu, 23 Dec 2010 22:09:15 +0100 Éric Araujo <merwok@netwok.org> wrote:
Le 23/12/2010 20:55, Antoine Pitrou a écrit :
def __index__(self): - """index(self)""" + """someobject[self]"""
This is misleading as to what the method actually does, Really? Unless I misunderstood the docs, __index__ is used when the object is used as an index (or with bin or oct, but I didn’t want to complicate the docstring, just fix it).
Well, it's only used for converting to an integer (also, it's used in more cases than just indexing), so "someobject[self]" is not the actual operation. Regards Antoine.
Am 23.12.2010 22:09, schrieb Éric Araujo:
Le 23/12/2010 20:55, Antoine Pitrou a écrit :
def __index__(self): - """index(self)""" + """someobject[self]"""
This is misleading as to what the method actually does, Really? Unless I misunderstood the docs, __index__ is used when the object is used as an index (or with bin or oct, but I didn’t want to complicate the docstring, just fix it).
In case Antoine's objection isn't clear yet: __index__ does *not* perform the actual indexing, as opposed to what the docstring suggests. Regards, Martin
participants (3)
-
"Martin v. Löwis"
-
Antoine Pitrou
-
Éric Araujo