Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #109716
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: UserList - which methods needs to be overriden? |
| Date | 2016-06-09 11:40 +0200 |
| Organization | None |
| Message-ID | <mailman.99.1465465213.2306.python-list@python.org> (permalink) |
| References | <b245d88e-9b90-bb90-bd2a-13ee82f7a5c8@shopzeus.com> <njbdhk$pv2$1@ger.gmane.org> |
Nagy László Zsolt wrote: > 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? How about set(dir(collections.UserList)) - set(dir(collections.Sequence)) > 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? I thought it was the other way round and UserList/UserDict were only kept for backwards-compatibility, but don't find anything in the docs to support this...
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: UserList - which methods needs to be overriden? Peter Otten <__peter__@web.de> - 2016-06-09 11:40 +0200
csiph-web