bpo-41747: Ensure all dataclass methods uses their parents' qualname (GH-22155)
* bpo-41747: Ensure all dataclass methods uses their parents' qualname
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
diff --git a/Lib/test/test_dataclasses.py b/Lib/test/test_dataclasses.py
index 7c1d9c5..8887eb6 100644
--- a/Lib/test/test_dataclasses.py
+++ b/Lib/test/test_dataclasses.py
@@ -1936,6 +1936,30 @@ class R:
self.assertEqual(new_sample.x, another_new_sample.x)
self.assertEqual(sample.y, another_new_sample.y)
+ def test_dataclasses_qualnames(self):
+ @dataclass(order=True, unsafe_hash=True, frozen=True)
+ class A:
+ x: int
+ y: int
+
+ self.assertEqual(A.__init__.__name__, "__init__")
+ for function in (
+ '__eq__',
+ '__lt__',
+ '__le__',
+ '__gt__',
+ '__ge__',
+ '__hash__',
+ '__init__',
+ '__repr__',
+ '__setattr__',
+ '__delattr__',
+ ):
+ self.assertEqual(getattr(A, function).__qualname__, f"TestCase.test_dataclasses_qualnames.<locals>.A.{function}")
+
+ with self.assertRaisesRegex(TypeError, r"A\.__init__\(\) missing"):
+ A()
+
class TestFieldNoAnnotation(unittest.TestCase):
def test_field_without_annotation(self):