You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While working on python/mypy#11047 I've noticed that there's an issue with typing.NamedTuple
Right now __init__ of typing.NamedTuple has type: def __init__(self, typename: str, fields: Iterable[Tuple[str, Any]] = ..., **kwargs: Any) -> None: ... which is not correct.
Why? Let's try to add both fields and kwargs:
>>>fromtypingimportNamedTuple>>>NamedTuple('a', (), f=int)
Traceback (mostrecentcalllast):
File"<stdin>", line1, in<module>File"/Users/sobolev/.pyenv/versions/3.9.1/lib/python3.9/typing.py", line1864, inNamedTupleraiseTypeError("Either list of fields or keywords"TypeError: EitherlistoffieldsorkeywordscanbeprovidedtoNamedTuple, notboth
But, I don't think that we should have def __init__(self, typename: str, fields: None = ..., **kwargs: Any) -> None: ... instead.
One more thing: is it Tuple[str, Any] or Tuple[str, type]? It is supposed to be types. But, it is not enforced anywhere (except mypy) as far as I know.
Activity
Fixes `__init__` of `typing.NamedTuple` (#6080)