3 ms·
It's great that we have simple/clean declarations for NamedTuples an (Data)classes now. But I wonder why they chose two different styles for creating them. Thi
by Rotareti 8y ago
It's great that we have simple/clean declarations for NamedTuples an (Data)classes now. But I wonder why they chose two different styles for creating them. This for NamedTuples:
from typing import NamedTuple
class Foo(NamedTuple):
bar: str
baz: int
and this for DataClasses:
@dataclass
class Foo:
bar: str
baz: int
- metalliqaz 8y agoWhen you write it that way it makes me wonder why there isn't a DataClass type
- joshuamorton 8y agoThe short answer is that the only way to do what dataclasses do as a base class is via python metaclasses, and you can only have one metaclass. So this way, you can dataclassify something that inherits from a metaclass.
- deleted 8y ago[deleted]