This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Incorrect doc for __getslice__
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: ashkop, docs@python, gdementen, python-dev
Priority: normal Keywords: patch

Created on 2015-03-12 15:24 by gdementen, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue23645.patch ashkop, 2015-03-13 08:39 review
Messages (4)
msg237947 - (view) Author: Gaëtan de Menten (gdementen) Date: 2015-03-12 15:24
The documentation for __getslice__ at https://docs.python.org/2/reference/datamodel.html#object.__getslice__ states: "Note that missing i or j in the slice expression are replaced by zero or sys.maxint, respectively."

However, in practice, it seems like it is replaced by sys.maxsize instead. This is obviously only a problem for 64bit versions of Python 2 since sys.maxint and sys.maxsize are the same on 32bit Python.

In [1]: class A(object):
   ...:     def __getslice__(self, i, j):
   ...:         print i, j
   ...:

In [2]: a = A()

In [3]: a[:]
0 9223372036854775807

In [4]: import sys

In [5]: sys.maxint
Out[5]: 2147483647

In [6]: sys.maxsize
Out[6]: 9223372036854775807L

In [7]: sys.version
Out[7]: '2.7.9 |Continuum Analytics, Inc.| (default, Dec 18 2014, 16:57:52) [MSC v.1500 64 bit (AMD64)]'
msg238014 - (view) Author: Alex Shkop (ashkop) * Date: 2015-03-13 08:39
This is true. In ceval.c default value for end index is PY_SSIZE_T_MAX. Whereas in sysmodule.c defined:

SET_SYS_FROM_STRING("maxsize",
                    PyInt_FromSsize_t(PY_SSIZE_T_MAX));
SET_SYS_FROM_STRING("maxint",
                    PyInt_FromLong(PyInt_GetMax()));

I added a patch that fixes documentation. But please note, that __getslice__ is deprecated since Python 2.0 and is no longer supported in Python 3. Use __getitem__ instead.
msg238015 - (view) Author: Gaëtan de Menten (gdementen) Date: 2015-03-13 09:00
Thanks for creating the patch! 

PS: I know it is deprecated. But I am stuck on Python2 for that project and my class inherits from numpy ndarray, so I do not have a choice...
msg238048 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-03-13 19:33
New changeset 3b91d834160f by Benjamin Peterson in branch '2.7':
the default is sys.maxsize not sys.maxint (closes #23645)
https://hg.python.org/cpython/rev/3b91d834160f
History
Date User Action Args
2022-04-11 14:58:13adminsetgithub: 67833
2015-03-13 19:33:06python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg238048

resolution: fixed
stage: patch review -> resolved
2015-03-13 18:20:26ezio.melottisettype: enhancement
stage: patch review
2015-03-13 09:00:48gdementensetmessages: + msg238015
2015-03-13 08:39:45ashkopsetfiles: + issue23645.patch

nosy: + ashkop
messages: + msg238014

keywords: + patch
2015-03-12 15:24:36gdementencreate