homepage

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.

Author eryksun
Recipients docs@python, eryksun, kt, rhettinger
Date 2014年06月17日.07:59:29
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1402991970.16.0.401963919786.issue21785@psf.upfronthosting.co.za>
In-reply-to
Content
Refer to the documentation for deprecated __getslice__ when slicing an instance of a classic class:
https://docs.python.org/2/reference/datamodel.html#object.__getslice__
The SLICE+3 implementation (apply_slice) calls PySequence_GetSlice if both index values can be converted to Py_ssize_t integers and if the type defines sq_slice (instance_slice for the "instance" type). The "instance" type is used for an instance of a classic class. This predates unification of Python classes and types.
apply_slice
http://hg.python.org/cpython/file/f89216059edf/Python/ceval.c#l4383
PySequence_GetSlice
http://hg.python.org/cpython/file/f89216059edf/Objects/abstract.c#l1995
instance_slice
http://hg.python.org/cpython/file/f89216059edf/Objects/classobject.c#l1177
A new-style class, i.e. a class that subclasses object, would have to define or inherit __getslice__ in order for the C sq_slice slot to be defined. But __getslice__ is deprecated and shouldn't be implemented unless you have to override it in a subclass of a built-in type. 
When sq_slice doesn't exist, apply_slice instead calls PyObject_GetItem with a slice object:
 class A(object):
 def __getitem__(self, index):
 return index.start
 def __len__(self):
 return 10
 >>> A()[-1:10]
 -1
By the way, you don't observe the behavior in Python 3 because it doesn't have classic classes, and the __getslice__, __setslice__, and __delslice__ methods are not in its data model.
History
Date User Action Args
2014年06月17日 07:59:30eryksunsetrecipients: + eryksun, rhettinger, docs@python, kt
2014年06月17日 07:59:30eryksunsetmessageid: <1402991970.16.0.401963919786.issue21785@psf.upfronthosting.co.za>
2014年06月17日 07:59:30eryksunlinkissue21785 messages
2014年06月17日 07:59:29eryksuncreate

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