]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-38761: Register WeakSet as a MutableSet (GH-17104)
authorRaymond Hettinger <rhettinger@users.noreply.github.com>
Mon, 11 Nov 2019 04:12:04 +0000 (20:12 -0800)
committerGitHub <noreply@github.com>
Mon, 11 Nov 2019 04:12:04 +0000 (20:12 -0800)
Lib/test/test_weakset.py
Lib/weakref.py
Misc/NEWS.d/next/Library/2019-11-10-13-40-33.bpo-38761.P1UUIZ.rst [new file with mode: 0644]

index 569facdd30c11c716aa50067dbcec299fa3c258d..49a9b5c3c658a89afb1dc490ea61c147d197ccbc 100644 (file)
@@ -2,6 +2,7 @@ import unittest
 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 @@ class TestWeakSet(unittest.TestCase):
     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()
index d17b3ed38eacb77f47e83dedde4474d6c09d3a67..e3c2ce2d9b8b865d9e3a8183c4fcd42f49571fba 100644 (file)
@@ -33,6 +33,9 @@ __all__ = ["ref", "proxy", "getweakrefcount", "getweakrefs",
            "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 (file)
index 0000000..4dde5eb
--- /dev/null
@@ -0,0 +1 @@
+WeakSet is now registered as a collections.abc.MutableSet.