Path: csiph.com!feeder.erje.net!1.us.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!news-1.dfn.de!news.dfn.de!news.informatik.hu-berlin.de!fu-berlin.de!uni-berlin.de!not-for-mail From: Michael Selik Newsgroups: comp.lang.python Subject: Re: UserList - which methods needs to be overriden? Date: Fri, 10 Jun 2016 13:23:35 +0000 Lines: 36 Message-ID: References: <1f4d1918-1e38-abba-aca7-830d91d35bd4@shopzeus.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: news.uni-berlin.de Wdyg2KjL7pOxpFMuwNJRIALu1DqWHx56WyaCYW6UAaIQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'implements': 0.07; 'override': 0.07; 'fix.': 0.09; 'loop.': 0.09; 'subclass': 0.09; 'subject:which': 0.09; 'def': 0.13; 'thu,': 0.15; '2016': 0.16; 'pop()': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'email addr:gmail.com>': 0.18; '>>>': 0.20; 'to:name:python-list@python.org': 0.20; 'to:2**1': 0.21; '(the': 0.22; 'header:In-Reply-To:1': 0.24; 'fri,': 0.27; 'message- id:@mail.gmail.com': 0.27; 'extend': 0.31; 'skip:s 30': 0.31; 'class': 0.33; 'michael': 0.33; 'list': 0.34; 'received:google.com': 0.35; 'quite': 0.35; '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; 'to:addr:python.org': 0.40; 'easy': 0.60; 'more': 0.63; 'nagy': 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=HrBC226bpit268hIAlol2ObYyU22Wru++syDqRdK/f8=; b=dKlIg8pdrmIMyg4dXM25b2OWunFC8be9sitbcv889/r8AlLwJ7JEYTPUqPv0JuDWJd nbeLbm/DsZbqFPQ2N/FlsUpsEDP92AGv6dkjUf7lhAbkMLHRjC3xk/o7iqqATgh5TSpu 41/Hv3z5Kq3YBzjb2IiOPudvESXL6W5/6LLcFmrZMU6EFbC/SxDTk/EMfTHLGsOeVLOp 4b8wNdYzMt09RoqhlAgvD9XFNKYEpoyhh9fGsT0ZLmtaBmeTpJQlfz7LWiewFbGdeoeO Z8onEfGnH4FJ4dXz0YlwAcpXXgM1zo3yobSXjpKuIM2ogZXF1b6Koom5p+i5zkh8mZpa siUw== 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=HrBC226bpit268hIAlol2ObYyU22Wru++syDqRdK/f8=; b=N8DcjqsAP90TKTHhBVLpSLYQ7mTyJnjBJPZQQHNDqi3tFuLfoow7jRVuFg0vzzpQiX ky+gjEqjqIQ5cHUuXas4sMhrmF45CaN3i9bi9SkvrhxnHkqBomHNW5iCWwVmDRyX9GJM xsNw8fvNpgS5tmj+b1JSBTUuUuqTGH7uP1otjHVt6hagX5f90+R/HrWcVMhAn67oRwT6 vcROcIGetLhnRZASZR0su6RVhiU66oPRNFtU6u9GA2dKB9ToyosqjFmRbDffF+g0/AWf 5FP4T6BklhyvVcthJ4GlygC9ino60mfDLKTJE5gBm8drOjG/IhIlFGHbRTB6kapgSVM7 fexA== X-Gm-Message-State: ALyK8tKyiwXGz4N2yPaKiHg/EjhvvBbZUtX3E9aV9Gddh8AvY0qnY7Pq2vbQGSfQk22ONpM1Eh2oqRbFOcX2mw== X-Received: by 10.140.106.228 with SMTP id e91mr1731305qgf.75.1465565024809; Fri, 10 Jun 2016 06:23:44 -0700 (PDT) In-Reply-To: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <1f4d1918-1e38-abba-aca7-830d91d35bd4@shopzeus.com> Xref: csiph.com comp.lang.python:109784 On Fri, Jun 10, 2016 at 9:18 AM Michael Selik wrote: > > > On Fri, Jun 10, 2016, 4:05 AM Nagy L=C3=A1szl=C3=B3 Zsolt > wrote: > >> 2016.06.10. 0:38 keltez=C3=A9ssel, Michael Selik =C3=ADrta: >> >> On Thu, Jun 9, 2016 at 5:07 AM Nagy L=C3=A1szl=C3=B3 Zsolt >> 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. >> >> 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-i= n >> extend() method of the list object is much more efficient. >> > If you find that extend is indeed a bottleneck, there's an easy fix. class NoisyList(MutableSequence): @noisy('extend') def extend(self, iterable): self.container.extend(iterable)