[Python-Dev] Nitpicking on UserList implementation

Peter Funk pf@artcom-gmbh.de
Wed, 22 Mar 2000 17:54:42 +0100 (MET)


Hi!

Please have a look at the following method cited from Lib/UserList.py:

    def __radd__(self, other):
        if isinstance(other, UserList):                    # <-- ? 
            return self.__class__(other.data + self.data)  # <-- ?
        elif isinstance(other, type(self.data)):
            return self.__class__(other + self.data)
        else:
            return self.__class__(list(other) + self.data)

The reference manual tells about the __r*__ methods: 

    """These functions are only called if the left operand does not 
       support the corresponding operation."""

So if the left operand is a UserList instance, it should always have
a __add__ method, which will be called instead of the right operands
__radd__.  So I think the condition 'isinstance(other, UserList)'
in __radd__ above will always evaluate to False and so the two lines
marked with '# <-- ?' seem to be superfluous.

But 'UserList' is so mature:  Please tell me what I've oveerlooked before
I make a fool of myself and submit a patch removing this two lines.

Regards, Peter
-- 
Peter Funk, Oldenburger Str.86, D-27777 Ganderkesee, Germany, Fax:+49 4222950260
office: +49 421 20419-0 (ArtCom GmbH, Grazer Str.8, D-28359 Bremen)