[pypy-issue] Issue #2136: obj[None:None] slice behavior differs from CPython (pypy/pypy)

Anders Kaseorg issues-reply at bitbucket.org
Sat Sep 12 21:34:51 CEST 2015


New issue 2136: obj[None:None] slice behavior differs from CPython
https://bitbucket.org/pypy/pypy/issues/2136/obj-none-none-slice-behavior-differs-from

Anders Kaseorg:

```
#!python
class A:
    def __getitem__(self, slice):
        print '__getitem__(%r)' % slice

A()[:]
# CPython 2.7.10 and PyPy 2.6.0: __getitem__(slice(0, 9223372036854775807, None))

A()[None:None]
# CPython 2.7.10: __getitem__(slice(None, None, None))
# PyPy 2.6.0: __getitem__(slice(0, 9223372036854775807, None))

class B(object):
    def __getitem__(self, slice):
        print '__getitem__(%r)' % slice

B()[:]
# CPython 2.7.10 and PyPy 2.6.0: __getitem__(slice(None, None, None))

B()[None:None]
# CPython 2.7.10 and PyPy 2.6.0: __getitem__(slice(None, None, None))

class C:
    def __getslice__(self, lower, upper):
        print '__getslice__(%r, %r)' % (lower, upper)

    def __getitem__(self, slice):
        print '__getitem__(%r)' % slice

C()[:]
# CPython 2.7.10 and PyPy 2.6.0: __getslice__(0, 9223372036854775807)

C()[None:None]
# CPython 2.7.10: __getitem__(slice(None, None, None))
# PyPy 2.6.0: __getslice__(0, 9223372036854775807)

class D(object):
    def __getslice__(self, lower, upper):
        print '__getslice__(%r, %r)' % (lower, upper)

    def __getitem__(self, slice):
        print '__getitem__(%r)' % slice

D()[:]
# CPython 2.7.10 and PyPy 2.6.0: __getslice__(0, 9223372036854775807)

D()[None:None]
# CPython 2.7.10: __getitem__(slice(None, None, None))
# PyPy 2.6.0: __getslice__(0, 9223372036854775807)
```

Similarly for `__setitem__`/`__setslice__` and `__delitem__`/`__delslice__`.




More information about the pypy-issue mailing list