Re: List slicing on Python 2.7

2018-03-15 Thread Ned Batchelder
On 3/15/18 12:35 PM, Peter Otten wrote: Ned Batchelder wrote: On 3/15/18 9:57 AM, Vlastimil Brom wrote: 2018-03-15 12:54 GMT+01:00 Arkadiusz Bulski : I have a custom class (a lazy list-like container) that needs to support slicing. The __getitem__ checks if index is of

Re: List slicing on Python 2.7

2018-03-15 Thread Peter Otten
Ned Batchelder wrote: > On 3/15/18 9:57 AM, Vlastimil Brom wrote: >> 2018-03-15 12:54 GMT+01:00 Arkadiusz Bulski : >>> I have a custom class (a lazy list-like container) that needs to support >>> slicing. The __getitem__ checks if index is of slice type, and does a >>> list

Re: List slicing on Python 2.7

2018-03-15 Thread Arkadiusz Bulski
Found the answer on stack overflow. Some types on some runtimes (builtins and on Python 2) use another method __getslice__ instead of __getitem__. https://docs.python.org/2/reference/datamodel.html#object.__getslice__ czw., 15 mar 2018 o 12:54 użytkownik Arkadiusz Bulski

Re: List slicing on Python 2.7

2018-03-15 Thread Ned Batchelder
On 3/15/18 9:57 AM, Vlastimil Brom wrote: 2018-03-15 12:54 GMT+01:00 Arkadiusz Bulski : I have a custom class (a lazy list-like container) that needs to support slicing. The __getitem__ checks if index is of slice type, and does a list comprehension over individual

Re: List slicing on Python 2.7

2018-03-15 Thread Vlastimil Brom
2018-03-15 12:54 GMT+01:00 Arkadiusz Bulski : > I have a custom class (a lazy list-like container) that needs to support > slicing. The __getitem__ checks if index is of slice type, and does a list > comprehension over individual integer indexes. The code works fine on >

List slicing on Python 2.7

2018-03-15 Thread Arkadiusz Bulski
I have a custom class (a lazy list-like container) that needs to support slicing. The __getitem__ checks if index is of slice type, and does a list comprehension over individual integer indexes. The code works fine on Python 3 but fails on 2.7, both CPython and PyPy. The print inside __getitem__