Slide 18
Slide 18 text
直接ソースを読む
typing.py#L2143
どうやら NamedTuple の実装は collections.namedtuple そのものらしい
実際に Type hint を付与しているのは 2218 行目
NamedTuple はこの後で紆余曲折あって関数とは言えない何かになっている
2212 def _make_nmtuple(name, types, module, defaults = ()):
2213 fields = [n for n, t in types]
2214 types = {n: _type_check(t, f"field {n} annotation must be a type")
2215 for n, t in types}
2216 nm_tpl = collections.namedtuple(name, fields,
2217 defaults=defaults, module=module)
2218 nm_tpl.__annotations__ = nm_tpl.__new__.__annotations__ = types
2219 return nm_tpl
...
2256 def NamedTuple(typename, fields=None, /, **kwargs):
...
2890 return _make_nmtuple(typename, fields, module=module)
Licensed under CC BY-SA 4.0 18