def keys(self): if self._pending_removals: self._commit_removals() with _IterationGuard(self): for k, wr in self.data.items(): if wr() is not None: yield k
def values(self): if self._pending_removals: self._commit_removals() with _IterationGuard(self): for wr in self.data.values(): obj = wr() if obj is not None: yield obj
def itervaluerefs(self): """Return an iterator that yields the weak references to the values. The references are not guaranteed to be 'live' at the time they are used, so the result of calling the references needs to be checked before being used. This can be used to avoid creating references that will cause the garbage collector to keep the values around longer than needed. """ if self._pending_removals: self._commit_removals() with _IterationGuard(self): yield from self.data.values()
def values(self): with _IterationGuard(self): for wr, value in self.data.items(): if wr() is not None: yield value
def keys(self): with _IterationGuard(self): for wr in self.data: obj = wr() if obj is not None: yield obj
def items(self): with _IterationGuard(self): for wr, value in self.data.items(): key = wr() if key is not None: yield key, value