Skip to content

Commit 84ac437

Browse files
authored
bpo-38761: Register WeakSet as a MutableSet (GH-17104)
1 parent af46450 commit 84ac437

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

Lib/test/test_weakset.py

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from weakref import WeakSet
33
import string
44
from collections import UserString as ustr
5+
from collections.abc import Set, MutableSet
56
import gc
67
import contextlib
78

@@ -437,6 +438,10 @@ def test_len_race(self):
437438
def test_repr(self):
438439
assert repr(self.s) == repr(self.s.data)
439440

441+
def test_abc(self):
442+
self.assertIsInstance(self.s, Set)
443+
self.assertIsInstance(self.s, MutableSet)
444+
440445

441446
if __name__ == "__main__":
442447
unittest.main()

Lib/weakref.py

+3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
"WeakSet", "WeakMethod", "finalize"]
3434

3535

36+
_collections_abc.Set.register(WeakSet)
37+
_collections_abc.MutableSet.register(WeakSet)
38+
3639
class WeakMethod(ref):
3740
"""
3841
A custom `weakref.ref` subclass which simulates a weak reference to
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
WeakSet is now registered as a collections.abc.MutableSet.

0 commit comments

Comments
 (0)