The signature in typing.pyi has extra fields verbose and rename, which are not in typing.py. From typing.pyi:
def __init__(self, typename: str, fields: Iterable[Tuple[str, Any]] = ..., *,
verbose: bool = ..., rename: bool = ..., **kwargs: Any) -> None: ...
From typing.py:
def __new__(self, typename, fields=None, **kwargs):
Which can also be seen in this example:
>>typing.NamedTuple('Example', verbose=bool, rename=bool).__annotations__
OrderedDict([('verbose', <class 'bool'>), ('rename', <class 'bool'>)])
Unsurprisingly, passing verbose=True (as implied by typing.pyi) causes an exception:
typing.NamedTuple('Example', verbose=True, other_field=int).__annotations__
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Program Files\Python37\lib\typing.py", line 1411, in __new__
return _make_nmtuple(typename, fields)
File "C:\Program Files\Python37\lib\typing.py", line 1326, in _make_nmtuple
types = [(n, _type_check(t, msg)) for n, t in types]
File "C:\Program Files\Python37\lib\typing.py", line 1326, in <listcomp>
types = [(n, _type_check(t, msg)) for n, t in types]
File "C:\Program Files\Python37\lib\typing.py", line 139, in _type_check
raise TypeError(f"{msg} Got {arg!r:.100}.")
TypeError: NamedTuple('Name', [(f0, t0), (f1, t1), ...]); each t must be a type Got True.
The signature in
typing.pyihas extra fields verbose and rename, which are not intyping.py. Fromtyping.pyi:From
typing.py:Which can also be seen in this example:
Unsurprisingly, passing
verbose=True(as implied bytyping.pyi) causes an exception: