builtin sequence subscript patch
Guido van Rossum
guido at CNRI.Reston.VA.US
Sat Jul 10 10:21:55 EDT 1999
> Someone posted that a class instance, with a __int__ method, could not
> be passed as a subscript of a built-in sequence. I think this is a bug
> since the build-in insert method of list can take a like object
> correctly.
>
> I'm enclosing a patch to correct this, based on the latest CVS code.
> I'll post the code to the newsgroup as well.
Michael, thanks for your patch. It solves your problem. But it
creates a new problem for me: you can now use floating point numbers
as list indices and it will truncate them. I don't like this feature,
and I'm worried that it will be hard to remove once it's there. So I
think it's better to use int() to cast your list indexing arguments
when you want to support objects with __int__ methods.
In Python 2.0, I want to change the __int__ interface into two
different ones: one that converts an existing integer-like value to
a real int, and one that tries to convert any (non-complex) numerical
value to a nearby integer. Then list indices will use the former
conversion, and you will be able to do what you want without an int()
cast yourself.
(And yes, I know that the insert() method sets a precedent, but I
don't want to move any further until I have the interface that lets me
do what's right!)
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-list
mailing list