mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
bpo-38761: Register WeakSet as a MutableSet (GH-17104)
This commit is contained in:
parent
af46450bb9
commit
84ac437658
3 changed files with 9 additions and 0 deletions
|
@ -2,6 +2,7 @@ import unittest
|
||||||
from weakref import WeakSet
|
from weakref import WeakSet
|
||||||
import string
|
import string
|
||||||
from collections import UserString as ustr
|
from collections import UserString as ustr
|
||||||
|
from collections.abc import Set, MutableSet
|
||||||
import gc
|
import gc
|
||||||
import contextlib
|
import contextlib
|
||||||
|
|
||||||
|
@ -437,6 +438,10 @@ class TestWeakSet(unittest.TestCase):
|
||||||
def test_repr(self):
|
def test_repr(self):
|
||||||
assert repr(self.s) == repr(self.s.data)
|
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__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -33,6 +33,9 @@ __all__ = ["ref", "proxy", "getweakrefcount", "getweakrefs",
|
||||||
"WeakSet", "WeakMethod", "finalize"]
|
"WeakSet", "WeakMethod", "finalize"]
|
||||||
|
|
||||||
|
|
||||||
|
_collections_abc.Set.register(WeakSet)
|
||||||
|
_collections_abc.MutableSet.register(WeakSet)
|
||||||
|
|
||||||
class WeakMethod(ref):
|
class WeakMethod(ref):
|
||||||
"""
|
"""
|
||||||
A custom `weakref.ref` subclass which simulates a weak reference to
|
A custom `weakref.ref` subclass which simulates a weak reference to
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
WeakSet is now registered as a collections.abc.MutableSet.
|
Loading…
Add table
Add a link
Reference in a new issue