summaryrefslogtreecommitdiff
path: root/Lib/_weakrefset.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2012-03-01 16:26:35 +0100
committerAntoine Pitrou <solipsis@pitrou.net>2012-03-01 16:26:35 +0100
commit0c0ad37012b89eadae4b64233638df6846629388 (patch)
tree890cbc600dc6964ad032dba14310c135a643b00b /Lib/_weakrefset.py
parent62aea7de15bafea3cafca005f98fc12f14f42394 (diff)
downloadcpython-0c0ad37012b89eadae4b64233638df6846629388.tar.gz
Issue #14159: Fix the len() of weak sets 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.py2
1 files changed, 1 insertions, 1 deletions
diff --git a/Lib/_weakrefset.py b/Lib/_weakrefset.py
index ffa5e31578..91077c5b95 100644
--- a/Lib/_weakrefset.py
+++ b/Lib/_weakrefset.py
@@ -63,7 +63,7 @@ class WeakSet(object):
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: