A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2006-February/060635.html below:

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

[Python-Dev] PEP for adding an sq_index slot so that any object, a or b, can be used in X[a:b] notationTravis E. Oliphant oliphant.travis at ieee.org
Thu Feb 9 22:40:29 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 what I'm proposing (except I'm not 
proposing to use the __int__ method because it is already used as 
coercion and doing this would allow floats to be used in slices which is 
a bad thing).  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

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4