Doc bug? customize getslice, setslice

Robert Brewer fumanchu at amor.org
Sat Feb 28 01:25:55 EST 2004


I was writing a subclass of dict today, and read the 2.3.3 docs
regarding __getslice__, __setslice__, and __delslice__. The getslice
discussion says it's deprecated since 2.0. Setslice and delslice don't
have that disclaimer. However, the rest of the page seems to imply that
they are also deprecated. In particular, the example code at the bottom
of the page skips defining slice methods if the version is 2.0 or over.

http://www.python.org/doc/current/ref/sequence-methods.html

class MyClass:
    ...
    def __getitem__(self, index):
        ...
    def __setitem__(self, index, value):
        ...
    def __delitem__(self, index):
        ...

    if sys.version_info < (2, 0):
        # They won't be defined if version is at least 2.0 final

        def __getslice__(self, i, j):
            return self[max(0, i):max(0, j):]
        def __setslice__(self, i, j, seq):
            self[max(0, i):max(0, j):] = seq
        def __delslice__(self, i, j):
            del self[max(0, i):max(0, j):]
    ...


Can someone confirm my theory that setslice and delslice are also
deprecated? Whether they are or not, I think that should be made more
clear, both in the discussion and the example code.

Should I file a doc bug?


Robert Brewer
MIS
Amor Ministries
fumanchu at amor.org




More information about the Python-list mailing list