diff options
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r-- | lib/sqlalchemy/util/_collections.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/sqlalchemy/util/_collections.py b/lib/sqlalchemy/util/_collections.py index 75e1727df..04409cfd9 100644 --- a/lib/sqlalchemy/util/_collections.py +++ b/lib/sqlalchemy/util/_collections.py @@ -676,16 +676,18 @@ class IdentitySet(object): class WeakSequence(object): def __init__(self, __elements=()): + def _remove(item, selfref=weakref.ref(self)): + self = selfref() + if self is not None: + self._storage.remove(item) + self._remove = _remove self._storage = [ - weakref.ref(element, self._remove) for element in __elements + weakref.ref(element, _remove) for element in __elements ] def append(self, item): self._storage.append(weakref.ref(item, self._remove)) - def _remove(self, ref): - self._storage.remove(ref) - def __len__(self): return len(self._storage) |