diff options
Diffstat (limited to 'lib/sqlalchemy')
| -rw-r--r-- | lib/sqlalchemy/util/_collections.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/sqlalchemy/util/_collections.py b/lib/sqlalchemy/util/_collections.py index b2e5c6250..a43115203 100644 --- a/lib/sqlalchemy/util/_collections.py +++ b/lib/sqlalchemy/util/_collections.py @@ -649,16 +649,23 @@ class IdentitySet(object): class WeakSequence(object): - def __init__(self, elements): + def __init__(self, __elements=()): self._storage = [ - weakref.ref(element) for element in elements + weakref.ref(element, self._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) + def __iter__(self): - return (obj for obj in (ref() for ref in self._storage) if obj is not None) + return (obj for obj in + (ref() for ref in self._storage) if obj is not None) def __getitem__(self, index): try: |
