diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2023-03-13 22:17:46 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-13 22:17:46 (GMT) |
commit | b0e221cfc881008212c037f510abab781884f6d9 (patch) | |
tree | 6438821482cefe896118910929309e24c3c0c1e9 /Lib/test/test_dataclasses.py | |
parent | a4fcd06c50bba8c58ee9fb0192f217b2ed821ae5 (diff) | |
download | cpython-b0e221cfc881008212c037f510abab781884f6d9.zip cpython-b0e221cfc881008212c037f510abab781884f6d9.tar.gz cpython-b0e221cfc881008212c037f510abab781884f6d9.tar.bz2 |
[3.11] gh-102069: Fix `__weakref__` descriptor generation for custom dataclasses (GH-102075) (#102662)
gh-102069: Fix `__weakref__` descriptor generation for custom dataclasses (GH-102075)
(cherry picked from commit d97757f793ea53dda3cc6882b4a92d3e921b17c9)
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
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 9af4377..3a24777 100644 --- a/Lib/test/test_dataclasses.py +++ b/Lib/test/test_dataclasses.py @@ -3076,6 +3076,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) @@ -3084,7 +3086,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: @@ -3150,7 +3154,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) @@ -3166,7 +3171,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: @@ -3181,7 +3187,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): |