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>
This commit is contained in:
Batuhan Taskaya 2020-10-21 16:49:22 +03:00 committed by GitHub
parent 9a1ad2cf02
commit c7437e2c02
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 2 deletions

View file

@ -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):