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


Groups > comp.lang.python > #109785

Re: UserList - which methods needs to be overriden?

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Michael Selik <michael.selik@gmail.com>
Newsgroups comp.lang.python
Subject Re: UserList - which methods needs to be overriden?
Date Fri, 10 Jun 2016 13:18:56 +0000
Lines 42
Message-ID <mailman.136.1465565066.2306.python-list@python.org> (permalink)
References <b245d88e-9b90-bb90-bd2a-13ee82f7a5c8@shopzeus.com> <CAGgTfkMakty7MohzRwLPpfRJikKBC0osTE83T0hZ9Scn+1NBOA@mail.gmail.com> <1f4d1918-1e38-abba-aca7-830d91d35bd4@shopzeus.com> <CAGgTfkMyW6R6Xi0ai9j833Opx7OnbutLc0pYLvVk2zRAjA+AYg@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
X-Trace news.uni-berlin.de f5d50ZkcGPvNOY7PYENfbghk7Kb14cy9xFU2Mrx1QRDA==
Return-Path <michael.selik@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.004
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'preferably': 0.05; 'that?': 0.05; 'implements': 0.07; 'override': 0.07; 'collections': 0.09; 'loop.': 0.09; 'methods,': 0.09; 'subclass': 0.09; 'subject:which': 0.09; ':-)': 0.12; 'thu,': 0.15; '2016': 0.16; 'overriding': 0.16; 'pop()': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'to:name:python- list@python.org': 0.20; 'to:2**1': 0.21; '(the': 0.22; 'wrote': 0.23; 'header:In-Reply-To:1': 0.24; 'fri,': 0.27; 'message- id:@mail.gmail.com': 0.27; 'object,': 0.27; 'fast.': 0.29; "i'm": 0.30; 'extend': 0.31; 'functional': 0.32; 'point': 0.33; 'michael': 0.33; "i'll": 0.33; 'list': 0.34; 'received:google.com': 0.35; 'skip:c 30': 0.35; 'quite': 0.35; 'but': 0.36; 'should': 0.36; 'there': 0.36; 'received:209.85': 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'method': 0.37; 'received:209': 0.38; 'why': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.40; 'your': 0.60; 'more': 0.63; 'beautiful': 0.66; 'sans': 0.72; 'discover': 0.73; 'nagy': 0.84; 'vera': 0.84; 'abc': 0.91; 'subject:needs': 0.93
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=PdBDMUlRX2bCF12NX/QsmP9cbdHCPWM/qTxR8zJbohI=; b=BGeZa8kpn943pTyZuYod8WRG+sV6UeaBe6zbNtMYFCrgF1NlGsKXAfwzwcOpNXHwz0 yT4Lb/vNI+laWRv7uDnJR3PntZddUWse8nsFJHj7qd7Rj6Tk/0jrDDg7qBrJZFIOhnDL jEnG3+TUHnaXDKGEVqGLVS0gP0q0aI47Q/GL2RLNFDNQ0FNq83RjvuNEtp6NnTA1d7sX hvAxOVmgn11M70BypnSbJkD1Uo0o58WEceH/yhz8H9d84gQvyEmmeKV0VL6tESLOn/9D ULBIPOGwmGuD2YtD73XWyjuWqmu0TTBBg7wwbJmFrtvLbjuaeXW0yk/oeaT89J5l2CrZ qFYA==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=PdBDMUlRX2bCF12NX/QsmP9cbdHCPWM/qTxR8zJbohI=; b=Zg8Ke9tdjhanf6gfWC7Ip43JFny6zicGD2181p4vjUm5S1k9F8urv/bg2nXDBKKPty cggmDlBrTHGVMFcE3WNvrFiSWkWCBA0p/7pMdFkWfTlL+sMVLWbS1hGSinrDkFSY94br r7HerSpOMR9Qx1nRJvH1Md4M3vdJhkpKMy5I0cPpPNMjgVE2W15s7V+6WtJgmYxZPiGf q0GNGhC2e/uUFPYZrFsdQpukAOclHrnU7FQpAw0kp8Nd3gEy01i4G1RcmlnqGcXt6lCR H8fyLRzQLRHXuRKf2cliF0GvRrP68BIs3+OuNAP26wr+D+UzaxNkuxkcrB9Z79U7W6fv aWgw==
X-Gm-Message-State ALyK8tLFxJrx300am/PXMmYbHwy61cwfnVqia+HtzkLVoKkpYSU/AGZVo3oZt6W6Udu6K+mUh2kwFH36XEcjXQ==
X-Received by 10.141.2.132 with SMTP id e126mr1816634qhd.55.1465564746487; Fri, 10 Jun 2016 06:19:06 -0700 (PDT)
In-Reply-To <1f4d1918-1e38-abba-aca7-830d91d35bd4@shopzeus.com>
X-Content-Filtered-By Mailman/MimeDel 2.1.22
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 <CAGgTfkMyW6R6Xi0ai9j833Opx7OnbutLc0pYLvVk2zRAjA+AYg@mail.gmail.com>
X-Mailman-Original-References <b245d88e-9b90-bb90-bd2a-13ee82f7a5c8@shopzeus.com> <CAGgTfkMakty7MohzRwLPpfRJikKBC0osTE83T0hZ9Scn+1NBOA@mail.gmail.com> <1f4d1918-1e38-abba-aca7-830d91d35bd4@shopzeus.com>
Xref csiph.com comp.lang.python:109785

Show key headers only | View raw


On Fri, Jun 10, 2016, 4:05 AM Nagy László Zsolt <gandalf@shopzeus.com>
wrote:

> 2016.06.10. 0:38 keltezéssel, Michael Selik írta:
>
> On Thu, Jun 9, 2016 at 5:07 AM Nagy László Zsolt <gandalf@shopzeus.com>
> wrote:
>
>> I would like to create a collections.UserList subclass that can notify
>> others when the list is mutated.
>>
>
> Why not subclass MutableSequence instead? The ABC will tell you which
> methods to override (the abstract ones). The mixin methods rely on those
> overrides.
>
> I'm not sure wich one is the best. Peter wrote that UserList was left in
> collections only for backward compatiblity. This might be a point against
> using UserList. The thing with MutableSequence is that it is quite
> inefficient. For example, it implements clear() by calling pop() in a loop.
> It implements extend() by calling append() in a loop. And we all know that
> the built-in extend() method of the list object is much more efficient. It
> is true that by overriding the abstract methods, I'll get a functional list
> like object, but we all know that
>
>  There should be one-- and preferably only one --obvious way to do it.
>
>
> Which one is that? :-)
>

The easiest, most beautiful way that is sufficiently fast. Use
MutableSequence until you discover that extend is actually the bottleneck
in your program.

>

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: UserList - which methods needs to be overriden? Michael Selik <michael.selik@gmail.com> - 2016-06-10 13:18 +0000

csiph-web