summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/util.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2007-12-14 05:53:18 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2007-12-14 05:53:18 +0000
commit0df750223a5f6ee4cfa987a4abd5ab4691007350 (patch)
tree89780e200d97f36a83d30c5da45122d211cb1075 /lib/sqlalchemy/util.py
parent273e48c9a95825541bd461a1d5402f2e65f95876 (diff)
downloadsqlalchemy-0df750223a5f6ee4cfa987a4abd5ab4691007350.tar.gz
- merged instances_yields branch r3908:3934, minus the "yield" part which remains slightly problematic
- cleanup of mapper._instance, query.instances(). mapper identifies objects which are part of the current load using a app-unique id on the query context. - attributes refactor; attributes now mostly use copy-on-modify instead of copy-on-load behavior, simplified get_history(), added a new set of tests - fixes to OrderedSet such that difference(), intersection() and others can accept an iterator - OrderedIdentitySet passes in OrderedSet to the IdentitySet superclass for usage in difference/intersection/etc. operations so that these methods actually work with ordering behavior. - query.order_by() takes into account aliased joins, i.e. query.join('orders', aliased=True).order_by(Order.id) - cleanup etc.
Diffstat (limited to 'lib/sqlalchemy/util.py')
-rw-r--r--lib/sqlalchemy/util.py36
1 files changed, 21 insertions, 15 deletions
diff --git a/lib/sqlalchemy/util.py b/lib/sqlalchemy/util.py
index 705168d20..3e26217c9 100644
--- a/lib/sqlalchemy/util.py
+++ b/lib/sqlalchemy/util.py
@@ -488,26 +488,30 @@ class OrderedSet(Set):
__or__ = union
def intersection(self, other):
- return self.__class__([a for a in self if a in other])
+ other = Set(other)
+ return self.__class__([a for a in self if a in other])
__and__ = intersection
def symmetric_difference(self, other):
- result = self.__class__([a for a in self if a not in other])
- result.update([a for a in other if a not in self])
- return result
+ other = Set(other)
+ result = self.__class__([a for a in self if a not in other])
+ result.update([a for a in other if a not in self])
+ return result
__xor__ = symmetric_difference
def difference(self, other):
- return self.__class__([a for a in self if a not in other])
+ other = Set(other)
+ return self.__class__([a for a in self if a not in other])
__sub__ = difference
def intersection_update(self, other):
- Set.intersection_update(self, other)
- self._list = [ a for a in self._list if a in other]
- return self
+ other = Set(other)
+ Set.intersection_update(self, other)
+ self._list = [ a for a in self._list if a in other]
+ return self
__iand__ = intersection_update
@@ -520,9 +524,9 @@ class OrderedSet(Set):
__ixor__ = symmetric_difference_update
def difference_update(self, other):
- Set.difference_update(self, other)
- self._list = [ a for a in self._list if a in self]
- return self
+ Set.difference_update(self, other)
+ self._list = [ a for a in self._list if a in self]
+ return self
__isub__ = difference_update
@@ -536,6 +540,7 @@ class IdentitySet(object):
def __init__(self, iterable=None):
self._members = _IterableUpdatableDict()
+ self._tempset = Set
if iterable:
for o in iterable:
self.add(o)
@@ -625,7 +630,7 @@ class IdentitySet(object):
result = type(self)()
# testlib.pragma exempt:__hash__
result._members.update(
- Set(self._members.iteritems()).union(_iter_id(iterable)))
+ self._tempset(self._members.iteritems()).union(_iter_id(iterable)))
return result
def __or__(self, other):
@@ -647,7 +652,7 @@ class IdentitySet(object):
result = type(self)()
# testlib.pragma exempt:__hash__
result._members.update(
- Set(self._members.iteritems()).difference(_iter_id(iterable)))
+ self._tempset(self._members.iteritems()).difference(_iter_id(iterable)))
return result
def __sub__(self, other):
@@ -669,7 +674,7 @@ class IdentitySet(object):
result = type(self)()
# testlib.pragma exempt:__hash__
result._members.update(
- Set(self._members.iteritems()).intersection(_iter_id(iterable)))
+ self._tempset(self._members.iteritems()).intersection(_iter_id(iterable)))
return result
def __and__(self, other):
@@ -691,7 +696,7 @@ class IdentitySet(object):
result = type(self)()
# testlib.pragma exempt:__hash__
result._members.update(
- Set(self._members.iteritems()).symmetric_difference(_iter_id(iterable)))
+ self._tempset(self._members.iteritems()).symmetric_difference(_iter_id(iterable)))
return result
def __xor__(self, other):
@@ -749,6 +754,7 @@ class OrderedIdentitySet(IdentitySet):
def __init__(self, iterable=None):
IdentitySet.__init__(self)
self._members = OrderedDict()
+ self._tempset = OrderedSet
if iterable:
for o in iterable:
self.add(o)