diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2012-03-01 16:26:35 +0100 |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2012-03-01 16:26:35 +0100 |
commit | 82c5a2efd164eb1649471ea64af956777e3099f0 (patch) | |
tree | 0beb3a3d23decd1b776120127c545fcb45391daa /Lib/_weakrefset.py | |
parent | d3148329913e050dcb55e40b268a64e0422bc261 (diff) | |
download | cpython-82c5a2efd164eb1649471ea64af956777e3099f0.tar.gz |
Issue #14159: Fix the len() of weak containers (WeakSet, WeakKeyDictionary, WeakValueDictionary) to return a better approximation when some objects are dead or dying.
Moreover, the implementation is now O(1) rather than O(n).
Thanks to Yury Selivanov for reporting.
Diffstat (limited to 'Lib/_weakrefset.py')
-rw-r--r-- | Lib/_weakrefset.py | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/Lib/_weakrefset.py b/Lib/_weakrefset.py index 42653699a3..f34aa864bc 100644 --- a/Lib/_weakrefset.py +++ b/Lib/_weakrefset.py @@ -63,7 +63,7 @@ class WeakSet: yield item def __len__(self): - return sum(x() is not None for x in self.data) + return len(self.data) - len(self._pending_removals) def __contains__(self, item): try: |