On Tue, Dec 8, 2009 at 10:49 PM, Jeremy Dunck <[email protected]> wrote:
> On Tue, Dec 8, 2009 at 8:38 PM, Luke Plant <[email protected]> wrote:
>> On Wednesday 09 December 2009 01:52:48 Jeremy Dunck wrote:
> ...
>>> You could also inspect the item to see if it's an instance of the
>>> .model; if not, fast path False.
>>>
>>> Which leads to a question of edge-case semantics -- "1 in qs"
>>>  checking for primary key value.  Good or bad?
>>
>> I think it's much better to leave __contains__ just doing an '=='
>> check, rather than anything clever which could surprise people.  (If
>> the developer is doing a test which is always going to return False,
>> it's a mistake, not an optimization opportunity).
>
> I see what you're saying.  I got there starting from the thought that
> __contains__ should perform a PK query if iteration hasn't started,
> rather than filling the results cache.  __nonzero__ is O(1), where
> "in" would be O(N).
>
> --
>
> You received this message because you are subscribed to the Google Groups 
> "Django developers" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/django-developers?hl=en.
>
>
>

I disagree that it should do a PK query in that case.  There is
precedent for doing it in pure python, even in cases where it is less
efficient, such as .count() vs. len().

Alex

-- 
"I disapprove of what you say, but I will defend to the death your
right to say it." -- Voltaire
"The people's good is the highest law." -- Cicero
"Code can always be simpler than you think, but never as simple as you
want" -- Me

--

You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.


Reply via email to