On Fri, Jun 10, 2016 at 9:18 AM Michael Selik <michael.se...@gmail.com> wrote:
> > > On Fri, Jun 10, 2016, 4:05 AM Nagy László Zsolt <gand...@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 <gand...@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. >> >> 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. >> > 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) -- https://mail.python.org/mailman/listinfo/python-list