python - getslice deprecated in Python2.6, but still in use when subclassing tuple? -
consider following example, executed under python 2.6.6 (which i'm unfortunately stuck @ moment):
>>> class a: ... def __getitem__(self, index): ... print(type(index)) ... def __getslice__(self, start, end): ... print("don't call me, i'm deprecated") ... >>> = a() >>> a[3] <type 'int'> >>> a[3:3] <type 'slice'>
as should be, slicing call __getitem__
. alter definition subclassing tuple
:
>>> class b(tuple): ... def __getitem__(self, index): ... print(type(index)) ... def __getslice__(self, start, end): ... print("don't call me, i'm deprecated") ... >>> b = b() >>> b[3] <type 'int'> >>> b[3:] don't call me, i'm deprecated
why happening?
due historical reasons, __getslice__
in places still gets used builtin types. tuple, used [i:j]
style syntax of slicing. see: http://bugs.python.org/issue2041 brief description , highlighted caveats in the getslice documentation
Comments
Post a Comment