mirror of
https://github.com/python/cpython.git
synced 2025-10-11 17:32:49 +00:00
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:
parent
9a1ad2cf02
commit
c7437e2c02
3 changed files with 36 additions and 2 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue