summaryrefslogtreecommitdiffstats
path: root/Lib/_weakrefset.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2012-03-01 15:26:35 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2012-03-01 15:26:35 (GMT)
commitc56bca31e9b7ac87a459a65680ee7ad454fd4f22 (patch)
treefeb3b4fe1a430192589fc1332c6d1d0a3dbc53aa /Lib/_weakrefset.py
parent4666ebd8fae8e115dc51b25d630481b15613e94d (diff)
downloadcpython-c56bca31e9b7ac87a459a65680ee7ad454fd4f22.zip
cpython-c56bca31e9b7ac87a459a65680ee7ad454fd4f22.tar.gz
cpython-c56bca31e9b7ac87a459a65680ee7ad454fd4f22.tar.bz2
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 ffa5e31..91077c5 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: