[Python-bugs-list] [ python-Bugs-456876 ] __getitem__ issues
noreply@sourceforge.net
noreply@sourceforge.net
Thu, 30 Aug 2001 07:35:22 -0700
Bugs item #456876, was opened at 2001-08-30 07:35
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=456876&group_id=5470
Category: Python Interpreter Core
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Tim Hochberg (tim-hochberg)
Assigned to: Nobody/Anonymous (nobody)
Summary: __getitem__ issues
Initial Comment:
(Python 2.1, Windows 2000)
__getitem__ is too consistent with __getslice__ and
not consistant enough with itself.
When getitem called in cases that would trigger
getslice if it were present, the slice object is
filled in a way that is consistent with getslice, but
not consistent with the rest of getitem's behaviour.
It's also not as useful as it could be.
Here's what getitem receives for various cases:
>>> a[0:1]
slice(0, 1, None)
>>> a[:1] # One of these things is not like the other
slice(0, 1, None)
>>> a[:1:1]
slice(None, 1, 1)
>>> a[::]
slice(None, None, None)
>>> a[:1:]
slice(None, 1, None)
In addition to being inconsistent, this behaviour is
less useful. Someone on the Numeric's list recently
ran into this as a stumbling block to subclassing
UserArray as a way to get arrays that are indexed
starting with one. (For easier translation of some
algorithms).
I see that this could potentially break some code, but
at this point most code that could be broken will
still be using getslice. Putting off fixing this will
only make it harder to fix as more people migrate to
the getitem protocol.
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=456876&group_id=5470