[Python-checkins] bpo-38761: Register WeakSet as a MutableSet (GH-17104)
Raymond Hettinger
webhook-mailer at python.org
Sun Nov 10 23:12:24 EST 2019
https://github.com/python/cpython/commit/84ac4376587e35d16b4d0977c4f330d9d04b690a
commit: 84ac4376587e35d16b4d0977c4f330d9d04b690a
branch: master
author: Raymond Hettinger <rhettinger at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2019-11-10T20:12:04-08:00
summary:
bpo-38761: Register WeakSet as a MutableSet (GH-17104)
files:
A Misc/NEWS.d/next/Library/2019-11-10-13-40-33.bpo-38761.P1UUIZ.rst
M Lib/test/test_weakset.py
M Lib/weakref.py
diff --git a/Lib/test/test_weakset.py b/Lib/test/test_weakset.py
index 569facdd30c11..49a9b5c3c658a 100644
--- a/Lib/test/test_weakset.py
+++ b/Lib/test/test_weakset.py
@@ -2,6 +2,7 @@
from weakref import WeakSet
import string
from collections import UserString as ustr
+from collections.abc import Set, MutableSet
import gc
import contextlib
@@ -437,6 +438,10 @@ def test_len_race(self):
def test_repr(self):
assert repr(self.s) == repr(self.s.data)
+ def test_abc(self):
+ self.assertIsInstance(self.s, Set)
+ self.assertIsInstance(self.s, MutableSet)
+
if __name__ == "__main__":
unittest.main()
diff --git a/Lib/weakref.py b/Lib/weakref.py
index d17b3ed38eacb..e3c2ce2d9b8b8 100644
--- a/Lib/weakref.py
+++ b/Lib/weakref.py
@@ -33,6 +33,9 @@
"WeakSet", "WeakMethod", "finalize"]
+_collections_abc.Set.register(WeakSet)
+_collections_abc.MutableSet.register(WeakSet)
+
class WeakMethod(ref):
"""
A custom `weakref.ref` subclass which simulates a weak reference to
diff --git a/Misc/NEWS.d/next/Library/2019-11-10-13-40-33.bpo-38761.P1UUIZ.rst b/Misc/NEWS.d/next/Library/2019-11-10-13-40-33.bpo-38761.P1UUIZ.rst
new file mode 100644
index 0000000000000..4dde5ebc3208c
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2019-11-10-13-40-33.bpo-38761.P1UUIZ.rst
@@ -0,0 +1 @@
+WeakSet is now registered as a collections.abc.MutableSet.
More information about the Python-checkins
mailing list