diff options
author | Batuhan Taskaya <batuhanosmantaskaya@gmail.com> | 2020-10-21 16:49:22 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-21 09:49:22 -0400 |
commit | c7437e2c0216e05fbf17bf96294cb20954e36e48 (patch) | |
tree | 6ac5b43803a48f26fae2b3992a9aa0fff958a3fc /Lib/test/test_dataclasses.py | |
parent | 9a1ad2cf02e52eccc3204e43752c8742d4c77f6b (diff) | |
download | cpython-c7437e2c0216e05fbf17bf96294cb20954e36e48.tar.gz cpython-c7437e2c0216e05fbf17bf96294cb20954e36e48.zip |
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>
Diffstat (limited to 'Lib/test/test_dataclasses.py')
-rw-r--r-- | Lib/test/test_dataclasses.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_dataclasses.py b/Lib/test/test_dataclasses.py index 7c1d9c568f4..8887eb6461b 100644 --- a/Lib/test/test_dataclasses.py +++ b/Lib/test/test_dataclasses.py @@ -1936,6 +1936,30 @@ class TestCase(unittest.TestCase): 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): |