[Python-Dev] Range __contains__ and objects with __index__ methods
Nick Coghlan
ncoghlan at gmail.com
Mon Dec 27 07:13:16 CET 2010
On Mon, Dec 27, 2010 at 11:52 AM, Terry Reedy <tjreedy at udel.edu> wrote:
> Return a converted to an integer. Equivalent to a.__index__()."
> comes close to implying equality (if possible).
>
> What are the actual used of .__index__?
PEP 357 gives the original rationale - it was to allow integer-like
objects (such as numpy scalars) to be used as sequence indices, as
well as slice parameters.
I would have to grep the source to get a full list of uses, but I
believe it is already used in at least those two cases, as well as for
sequence repetition (via '*') and to identify permitted inputs to
bin/oct/hex.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-Dev
mailing list