[issue8529] subclassing builtin class (str, unicode, list...) needs to override __getslice__

Florent Xicluna report at bugs.python.org
Sun Apr 25 19:01:54 CEST 2010


New submission from Florent Xicluna <florent.xicluna at gmail.com>:

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[::]

----------
components: Interpreter Core
messages: 104148
nosy: flox
priority: normal
severity: normal
status: open
title: subclassing builtin class (str, unicode, list...) needs to override __getslice__
type: behavior
versions: Python 2.7

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue8529>
_______________________________________


More information about the Python-bugs-list mailing list