Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #109716

Re: UserList - which methods needs to be overriden?

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Peter Otten <__peter__@web.de>
Newsgroups comp.lang.python
Subject Re: UserList - which methods needs to be overriden?
Date Thu, 09 Jun 2016 11:40:03 +0200
Organization None
Lines 29
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>
Mime-Version 1.0
Content-Type text/plain; charset="UTF-8"
Content-Transfer-Encoding 8Bit
X-Trace news.uni-berlin.de 91LFt6T5CWEcTvTMJ0unGw/usHJUlvE7cVCZFH7YVw6A==
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'finally:': 0.05; 'override': 0.07; 'type,': 0.07; 'inherited': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subclass': 0.09; 'subject:which': 0.09; 'collections.': 0.16; 'empty.': 0.16; 'pop()': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'received:t-ipconnect.de': 0.16; 'sources,': 0.16; 'userdict': 0.16; 'wrote:': 0.16; 'proposed': 0.20; 'seems': 0.23; 'header :User-Agent:1': 0.26; '(which': 0.26; 'header:X-Complaints-To:1': 0.26; 'figure': 0.27; 'checking': 0.27; 'sequence': 0.27; 'container': 0.29; 'modified,': 0.29; "i'm": 0.30; 'classes': 0.30; 'too.': 0.30; 'becomes': 0.30; 'checked': 0.31; 'skip:s 30': 0.31; 'source': 0.33; "i'll": 0.33; 'list': 0.34; 'but': 0.36; 'there': 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'method': 0.37; 'received:org': 0.37; 'thought': 0.37; 'anything': 0.38; 'sure': 0.39; 'easily': 0.39; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'some': 0.40; 'ever': 0.60; 'skip:u 10': 0.61; 'nagy': 0.84; 'this...': 0.84; 'subject:needs': 0.93
X-Injected-Via-Gmane http://gmane.org/
X-Gmane-NNTP-Posting-Host p57bd9048.dip0.t-ipconnect.de
User-Agent KNode/4.13.3
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.22
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <njbdhk$pv2$1@ger.gmane.org>
X-Mailman-Original-References <b245d88e-9b90-bb90-bd2a-13ee82f7a5c8@shopzeus.com>
Xref csiph.com comp.lang.python:109716

Show key headers only | View raw


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


Thread

Re: UserList - which methods needs to be overriden? Peter Otten <__peter__@web.de> - 2016-06-09 11:40 +0200

csiph-web