Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #109716 > unrolled thread
| Started by | Peter Otten <__peter__@web.de> |
|---|---|
| First post | 2016-06-09 11:40 +0200 |
| Last post | 2016-06-09 11:40 +0200 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: UserList - which methods needs to be overriden? Peter Otten <__peter__@web.de> - 2016-06-09 11:40 +0200
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Date | 2016-06-09 11:40 +0200 |
| Subject | Re: UserList - which methods needs to be overriden? |
| Message-ID | <mailman.99.1465465213.2306.python-list@python.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 top | Article view | comp.lang.python
csiph-web