Issue 8529: subclassing builtin class (str, unicode, list...) needs to override getslice (original) (raw)

Created on 2010-04-25 17:01 by flox, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (4)
msg104148 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2010-04-25 17:01
It looks like a bug, because __getslice__ is deprecated since 2.0. If you subclass a builtin type and override the __getitem__ method, you need to override the (deprecated) __getslice__ method too. And if you run your program with "python -3", it Example script: class Upper(unicode): def __getitem__(self, index): return unicode.__getitem__(self, index).upper() #def __getslice__(self, i, j): #return self[i:j:] if __name__ == '__main__': text = Upper('Lorem ipsum') print text[:] print text[::]
msg104170 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2010-04-25 21:44
This is because unicode implements __getslice__.
msg104171 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2010-04-25 22:17
OK, but it yields Python 3 DeprecationWarning in the subclass. And there's no workaround to get rid of the deprecation. If it is the correct behaviour, maybe some words could be added about subclassing builtin types: http://docs.python.org/reference/datamodel.html#additional-methods-for-emulation-of-sequence-types
msg104172 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2010-04-25 22:18
OK, I said nothing, it is already in the doc. :-)
History
Date User Action Args
2022-04-11 14:57:00 admin set github: 52775
2010-04-25 22🔞30 flox set messages: +
2010-04-25 22:17:28 flox set messages: +
2010-04-25 21:44:39 benjamin.peterson set status: open -> closednosy: + benjamin.petersonmessages: + resolution: not a bug
2010-04-25 17:01:51 flox create