summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2019-09-09 16:24:16 (GMT)
committerGitHub <noreply@github.com>2019-09-09 16:24:16 (GMT)
commit78d15faf6c522619098e94be3e7f6d88a9e61123 (patch)
treea7d4dc8890f16df333a3c17b13158ed15fd7dfa3 /Lib
parentb6ef8f2beb90678a4a54218d6169040afbbf9fe1 (diff)
downloadcpython-78d15faf6c522619098e94be3e7f6d88a9e61123.zip
cpython-78d15faf6c522619098e94be3e7f6d88a9e61123.tar.gz
cpython-78d15faf6c522619098e94be3e7f6d88a9e61123.tar.bz2
bpo-38006: Avoid closure in weakref.WeakValueDictionary (GH-15641)
weakref.WeakValueDictionary defines a local remove() function used as callback for weak references. This function was created with a closure. Modify the implementation to avoid the closure. (cherry picked from commit a2af05a0d3f0da06b8d432f52efa3ecf29038532) Co-authored-by: Victor Stinner <vstinner@redhat.com>
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_weakref.py5
-rw-r--r--Lib/weakref.py4
2 files changed, 7 insertions, 2 deletions
diff --git a/Lib/test/test_weakref.py b/Lib/test/test_weakref.py
index 6f15c03..d9e1b20 100644
--- a/Lib/test/test_weakref.py
+++ b/Lib/test/test_weakref.py
@@ -1785,6 +1785,11 @@ class MappingTestCase(TestBase):
# copying should not result in a crash.
self.check_threaded_weak_dict_copy(weakref.WeakValueDictionary, True)
+ @support.cpython_only
+ def test_remove_closure(self):
+ d = weakref.WeakValueDictionary()
+ self.assertIsNone(d._remove.__closure__)
+
from test import mapping_tests
diff --git a/Lib/weakref.py b/Lib/weakref.py
index 8d71af6..9d70089 100644
--- a/Lib/weakref.py
+++ b/Lib/weakref.py
@@ -108,12 +108,12 @@ class WeakValueDictionary(_collections_abc.MutableMapping):
else:
# Atomic removal is necessary since this function
# can be called asynchronously by the GC
- _atomic_removal(d, wr.key)
+ _atomic_removal(self.data, wr.key)
self._remove = remove
# A list of keys to be removed
self._pending_removals = []
self._iterating = set()
- self.data = d = {}
+ self.data = {}
self.update(other, **kw)
def _commit_removals(self):