On Friday 05 May 2006 12:47, Michael Radziej wrote: > Hi, > > what about providing class functions QuerySet.union(cls, qset_list), > QuerySet.intersection(cls, qset_list), both returning cls, such as: > > def union(cls, qset_list): > """Returns the union of a list of QuerySets, a QuerySet.""" > return reduce(cls.__or__, qset_list) > > union = classmethod(union) > > A class method, since you might want to subclass QuerySet (I do).
Yes, I agree we should complete the parallel with Python sets. With Python built-in sets, 'some_set.union(iterable)' is exactly the same as 'some_set | set(iterable)' (and similarly with 'intersection' and '&') so you have this identity: some_set.union(other_set) == some_set | other_set Your example code has different semantics: some_qset.union([other_qset]) == some_qset | other_qset Also, I'm not sure why it needs to be a class method. Instead of using cls.__or__, you could use operator.or_ Luke -- "I think you ought to know I'm feeling very depressed." (Marvin the paranoid android) Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/ --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
