3 ms·
> Dataclasses is notable because it's the only example (I'm aware of) of type hints effecting runtime behavior as part of the stdlib. FWIW, `typing.NamedTuple`
by amethyst 3y ago
> Dataclasses is notable because it's the only example (I'm aware of) of type hints effecting runtime behavior as part of the stdlib.
FWIW, `typing.NamedTuple` did this in Python 3.5, three years before dataclasses was introduced in 3.7.
class Foo(typing.NamedTuple):
a: int
b: str
f = Foo(a=1, b="hello")
print(f.b) # "hello"
- BeefySwain 3y agoGreat catch, how could I forget!
- auscompgeek 3y agoVariable annotations were only added in Python 3.6. Defining a typed namedtuple in Python 3.5 looked like this: Foo = typing.NamedTuple('Foo', [('a', int), ('b', str)])