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


Groups > comp.lang.python > #109785 > unrolled thread

Re: UserList - which methods needs to be overriden?

Started byMichael Selik <michael.selik@gmail.com>
First post2016-06-10 13:18 +0000
Last post2016-06-10 13:18 +0000
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.


Contents

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

#109785 — Re: UserList - which methods needs to be overriden?

FromMichael Selik <michael.selik@gmail.com>
Date2016-06-10 13:18 +0000
SubjectRe: UserList - which methods needs to be overriden?
Message-ID<mailman.136.1465565066.2306.python-list@python.org>
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.

>

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web