typing.NamedTuple
collections.namedtuple() の型付き版です。
code:python
>> from typing import NamedTuple
>> class Employee(NamedTuple):
... name: str
... id: int
>> e1 = Employee("taro", 101)
>> e1
Employee(name='taro', id=101)
>> e1.id
101
>> e1.id = 102
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: can't set attribute
code:python
>> object.__setattr__(e1, "id", 102)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: can't set attribute
しかしtupleなのでunpackできてしまう
code:python
>> a, b = e1
>> a
'taro'
>> b
101
dataclass(frozen=True)とどっちもどっちという感じ(どちらも図抜けていない)