Files
pytest2/testing/example_scripts/dataclasses/test_compare_recursive_dataclasses.py
Bruno Oliveira 878af85aef mypy: disallow untyped defs by default (#11862)
Change our mypy configuration to disallow untyped defs by default, which ensures *new* files added to the code base are fully typed.

To avoid having to type-annotate everything now, add `# mypy: allow-untyped-defs` to files which are not fully type annotated yet.

As we fully type annotate those modules, we can then just remove that directive from the top.
2024-01-28 10:12:42 -03:00

46 lines
578 B
Python

# mypy: allow-untyped-defs
from dataclasses import dataclass
@dataclass
class S:
a: int
b: str
@dataclass
class C:
c: S
d: S
@dataclass
class C2:
e: C
f: S
@dataclass
class C3:
g: S
h: C2
i: str
j: str
def test_recursive_dataclasses():
left = C3(
S(10, "ten"),
C2(C(S(1, "one"), S(2, "two")), S(2, "three")),
"equal",
"left",
)
right = C3(
S(20, "xxx"),
C2(C(S(1, "one"), S(2, "yyy")), S(3, "three")),
"equal",
"right",
)
assert left == right