Re:The Data Classes Decorator
by lcnmrn on Sunday December 12, 2021 @08:18AM
(#29529382)
NamedTuples work with and without type hints, but Dataclasses only work with type hints: https://subreply.com/reply/lsk
[ Parent
| on HN ]
Re:The Data Classes Decorator
by ericvsmith on Sunday December 12, 2021 @12:54PM
(#29531790)
dataclasses author here.
That's not true. You can use make_dataclass the same way you can use namedtuple:
>>> from dataclasses import make_dataclass
>>> A = make_dataclass("A", ["x", "y", "z"])
>>> A(1, 2, 3)
A(x=1, y=2, z=3)
It is true that if you want to use @dataclass you have to use annotations, just the way you do with typing.NamedTuple. But as others have noted, the annotation is mostly ignored.[edited for formatting]