UserList - which methods needs to be overriden?

Nagy László Zsolt gandalf at shopzeus.com
Thu Jun 9 05:04:46 EDT 2016


   Hi,

I would like to create a collections.UserList subclass that can notify
others when the list is mutated. I'm not sure which methods I need to
override. I have checked the sources, and it seems difficult to figure
out which methods needs to be overriden. For example,
MutableSequence.extend is just a for loop that calls append(). Also, the
clear() method just calls pop() until the sequence becomes empty. But
UserList overrides extend, so if I ever want to know when the list is
modified, I need to override extend() too. There are lots of base
classes (UserList, MutableSequence, Sequence ) etc and some mutating
methods might be inherited from those. I'll also have to do this for
UserDict (which is a MutableMapping, which is a Mapping).

Is there a way to easily find out which methods of are mutating the
collection? Other than going over the source and checking all (normal
and inherited) methods?

And finally: set is a built in container type, but we don't have a
UserSet in collections. Was it ever proposed to be added to collections?

Thanks,

   Laszlo







More information about the Python-list mailing list