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


Groups > comp.lang.python > #41044

Re: Interesting list() un-optimization

From Roy Smith <roy@panix.com>
Newsgroups comp.lang.python
Subject Re: Interesting list() un-optimization
Date 2013-03-10 18:34 -0400
Organization PANIX Public Access Internet and UNIX, NYC
Message-ID <roy-9B5401.18345810032013@70-1-84-166.pools.spcsdns.net> (permalink)
References <roy-572C99.22201106032013@70-1-84-166.pools.spcsdns.net> <roy-87E0C0.09050910032013@70-1-84-166.pools.spcsdns.net> <mailman.3167.1362951587.2939.python-list@python.org>

Show all headers | View raw


In article <mailman.3167.1362951587.2939.python-list@python.org>,
 Terry Reedy <tjreedy@udel.edu> wrote:

> > It turns out, we don't actually use QuerySet in our models.  We've
> > defined our own QuerySet subclass which adds a few convenience methods.
> > Adding
> >
> >      def __len__(self):
> >          raise NotImplemented
> >
> > to our subclass should do the job.  It looks like list() respects that,
> > calls __iter__(), and does the right thing.  I can't find any place
> > where that behavior for list() is documented,
> 
> It is a cpython implementation detail that probably has changed with the 
> versions.

Yeah, that's what I was afraid of.  The "obvious" solution of:

class QuerySet(mongoengine.queryset.QuerySet):
    def __init__(self, document, collection):
        super(QuerySet, self).__init__(document, collection)
        [...]
        del self.__len__

results in:

[rest of stack dump elided]
    del self.__len__
AttributeError: __len__

which I don't understand.

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


Thread

Interesting list() un-optimization Roy Smith <roy@panix.com> - 2013-03-06 22:20 -0500
  Re: Interesting list() un-optimization Dave Angel <davea@davea.name> - 2013-03-06 22:38 -0500
  Re: Interesting list() un-optimization Tim Chase <python.list@tim.thechases.com> - 2013-03-06 21:57 -0600
  Re: Interesting list() un-optimization Kev Dwyer <kevin.p.dwyer@gmail.com> - 2013-03-07 07:31 +0000
  Re: Interesting list() un-optimization Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de> - 2013-03-07 11:22 +0000
  Re: Interesting list() un-optimization Ian Kelly <ian.g.kelly@gmail.com> - 2013-03-07 09:00 -0700
  Re: Interesting list() un-optimization Christian Heimes <christian@python.org> - 2013-03-07 17:20 +0100
  Re: Interesting list() un-optimization Ian Kelly <ian.g.kelly@gmail.com> - 2013-03-07 10:31 -0700
  Re: Interesting list() un-optimization Stefan Behnel <stefan_ml@behnel.de> - 2013-03-07 20:19 +0100
  Re: Interesting list() un-optimization Ian Kelly <ian.g.kelly@gmail.com> - 2013-03-07 13:26 -0700
  Re: Interesting list() un-optimization Terry Reedy <tjreedy@udel.edu> - 2013-03-07 15:29 -0500
  Re: Interesting list() un-optimization Terry Reedy <tjreedy@udel.edu> - 2013-03-07 15:34 -0500
  Re: Interesting list() un-optimization Wolfgang Maier <wolfgang.maier@biologie.uni-freiburg.de> - 2013-03-07 20:41 +0000
  Re: Interesting list() un-optimization Terry Reedy <tjreedy@udel.edu> - 2013-03-07 17:53 -0500
  Re: Interesting list() un-optimization Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-08 17:59 +0000
    Re: Interesting list() un-optimization Roy Smith <roy@panix.com> - 2013-03-08 13:45 -0500
  Re: Interesting list() un-optimization Roy Smith <roy@panix.com> - 2013-03-10 09:05 -0400
    Re: Interesting list() un-optimization Terry Reedy <tjreedy@udel.edu> - 2013-03-10 17:39 -0400
      Re: Interesting list() un-optimization Roy Smith <roy@panix.com> - 2013-03-10 18:34 -0400
        Re: Interesting list() un-optimization Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-10 23:35 +0000
          Re: Interesting list() un-optimization Roy Smith <roy@panix.com> - 2013-03-10 19:50 -0400

csiph-web