3 ms·
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
by ericvsmith 5y ago
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]
- lcnmrn 5y agoCan you assign defaults with make_dataclass() but no types?