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.
