[issue7532] Extended slicing with classic class behaves strangely
Mark Dickinson
report at bugs.python.org
Thu Dec 17 21:36:52 CET 2009
Mark Dickinson <dickinsm at gmail.com> added the comment:
Hmm. This doesn't look like something that's easy to fix without affecting existing correct code; given
that the behaviour has been around for a while (I'm not sure exactly how long), and that the issue is gone
in 3.x, I suspect it may not be worth trying.
Analysis: for classic classes, the ceval loop calls PySequence_GetSlice, which corrects the negative
indices by adding the length of the sequence (as described in the docs) and then calls the
tp_as_sequence->sq_slice slot on the type. That ends up calling instance_slice (in
Objects/classobject.c), which discovers that the class doesn't implement __getslice__ and so passes the
adjusted slice on to the __getitem__ method.
I'm not sure how this could be changed to get the correct behaviour: PySequence_GetSlice would somehow
need to know that it was going to end up calling __getitem__ rather than __getslice__.
Raymond, any thoughts?
----------
nosy: +mark.dickinson, rhettinger
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue7532>
_______________________________________
More information about the Python-bugs-list
mailing list