diff options
author | Nikita Sobolev <mail@sobolevn.me> | 2023-03-14 00:42:05 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-13 15:42:05 -0600 |
commit | d97757f793ea53dda3cc6882b4a92d3e921b17c9 (patch) | |
tree | a5bc4852eaa2d04af37975ae1f1f9b13c4757ece /Lib/test/test_dataclasses.py | |
parent | 71e37d907905b0504c5bb7b25681adeea2157492 (diff) | |
download | cpython-d97757f793ea53dda3cc6882b4a92d3e921b17c9.tar.gz cpython-d97757f793ea53dda3cc6882b4a92d3e921b17c9.zip |
gh-102069: Fix `__weakref__` descriptor generation for custom dataclasses (#102075)
Diffstat (limited to 'Lib/test/test_dataclasses.py')
-rw-r--r-- | Lib/test/test_dataclasses.py | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/Lib/test/test_dataclasses.py b/Lib/test/test_dataclasses.py index 46d4e0fedad..46f33043c27 100644 --- a/Lib/test/test_dataclasses.py +++ b/Lib/test/test_dataclasses.py @@ -3175,6 +3175,8 @@ class TestSlots(unittest.TestCase): with self.assertRaisesRegex(TypeError, "cannot create weak reference"): weakref.ref(a) + with self.assertRaises(AttributeError): + a.__weakref__ def test_slots_weakref(self): @dataclass(slots=True, weakref_slot=True) @@ -3183,7 +3185,9 @@ class TestSlots(unittest.TestCase): self.assertIn("__weakref__", A.__slots__) a = A(1) - weakref.ref(a) + a_ref = weakref.ref(a) + + self.assertIs(a.__weakref__, a_ref) def test_slots_weakref_base_str(self): class Base: @@ -3249,7 +3253,8 @@ class TestSlots(unittest.TestCase): self.assertIn("__weakref__", Base.__slots__) self.assertNotIn("__weakref__", A.__slots__) a = A(1) - weakref.ref(a) + a_ref = weakref.ref(a) + self.assertIs(a.__weakref__, a_ref) def test_weakref_slot_subclass_no_weakref_slot(self): @dataclass(slots=True, weakref_slot=True) @@ -3265,7 +3270,8 @@ class TestSlots(unittest.TestCase): self.assertIn("__weakref__", Base.__slots__) self.assertNotIn("__weakref__", A.__slots__) a = A(1) - weakref.ref(a) + a_ref = weakref.ref(a) + self.assertIs(a.__weakref__, a_ref) def test_weakref_slot_normal_base_weakref_slot(self): class Base: @@ -3280,7 +3286,8 @@ class TestSlots(unittest.TestCase): self.assertIn("__weakref__", Base.__slots__) self.assertNotIn("__weakref__", A.__slots__) a = A(1) - weakref.ref(a) + a_ref = weakref.ref(a) + self.assertIs(a.__weakref__, a_ref) class TestDescriptors(unittest.TestCase): |