[Python-Dev] PEP for adding an sq_index slot so that any object, a or b, can be used in X[a:b] notation

Travis E. Oliphant oliphant.travis at ieee.org
Thu Feb 9 22:39:07 CET 2006


Bengt Richter wrote:
>>>> How about if SLICE byte code interpretation would try to call
> obj.__int__() if passed a non-(int,long) obj ? Would that cover your use case?
>
I believe that this is pretty much exactly what I'm proposing. The 
apply_slice and assign_slice functions in ceval.c are called for the 
SLICE and STORE_SLICE and DELETE_SLICE opcodes.
> BTW the slice type happily accepts anything for start:stop:step I believe,
> and something[slice(whatever)] will call something.__getitem__ with the slice
> instance, though this is neither a fast nor nicely spelled way to customize.
>
Yes, the slice object itself takes whatever you want. However, Python 
special-cases what happens for X[a:b] *if* X as the sequence-protocol 
defined. This is the code-path I'm trying to enhance.
-Travis


More information about the Python-Dev mailing list

AltStyle によって変換されたページ (->オリジナル) /