Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: =?UTF-8?Q?Nagy_L=c3=a1szl=c3=b3_Zsolt?= Newsgroups: comp.lang.python Subject: Re: UserList - which methods needs to be overriden? Date: Fri, 10 Jun 2016 10:04:38 +0200 Lines: 28 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 ASoO5SA+gum2/eyLXxq4SwycVaJ5cVJmcZVQ9hsouJ2w== Return-Path: 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; '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; '0.5em;': 0.16; '2016': 0.16; 'baseline;': 0.16; 'box-shadow:': 0.16; 'break-word;': 0.16; 'inherit;': 0.16; 'monospace,': 0.16; 'overriding': 0.16; 'pop()': 0.16; 'pre-wrap;': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'word-wrap:': 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; 'object,': 0.27; "i'm": 0.30; 'functional': 0.32; 'point': 0.33; 'michael': 0.33; "i'll": 0.33; 'list': 0.34; 'quite': 0.35; 'but': 0.36; 'should': 0.36; 'there': 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'subject:: ': 0.37; 'skip:& 10': 0.37; 'method': 0.37; 'why': 0.39; 'skip:- 20': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.40; 'color:': 0.60; 'more': 0.63; 'sans- serif;': 0.67; '15px;': 0.72; 'sans': 0.72; 'nagy': 0.84; 'vera': 0.84; 'abc': 0.91; 'start;': 0.91; 'subject:needs': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shopzeus.com; s=shopzeus_com; t=1465545936; bh=zVeCUI2NuhkOfHj9BEmKsLl1bGshbNqYRdPdrs3HNGU=; h=Subject:To:References:From:Date:In-Reply-To:From; b=KYjGbmwAXkuYUvht+pJu7EWYBMztjVbulWdkJOD/Yihr2mSpWiOYMZiBj7/Yt23ox +JMWu3Q2qDnEDwG/NPJDWomw3bGTMeck4ry/yfQ5liWc9M72VsWp1YbpPYEVUOWcgy 1nET1SveJxWeXo/T1QKSj+Tx5gPsjpO2rnjGjIQAaxlTSfMOR+nSLVoIuVKcR+/Ag3 XAWPpzVGcijMUrVrLho8YFcxZD2mcWUY1IL9YJ9JE25DDsF67ufoTzK0LZ6xCsCLeZ Spye0bYITHh1BgHui+ceN2DFNJa+ctePY+qX6Tu9rX5Og2Mv5P/wdOjKIdTUbY1npi Sb9oT1CcLgoMw== 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: <1f4d1918-1e38-abba-aca7-830d91d35bd4@shopzeus.com> X-Mailman-Original-References: Xref: csiph.com comp.lang.python:109775 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 not= ify > 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? :-)