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
{{ message }}
Repository navigation
typing.NamedTuple should add annotations to its constructor (__new__) parameters. #75189
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2019-06-03.23:46:42.059>created_at=<Date2017-07-24.09:07:47.250>labels= ['type-feature', 'library']
title='typing.NamedTuple should add annotations to its constructor (__new__) parameters.'updated_at=<Date2019-06-04.10:00:03.368>user='https://github.com/anntzer'
Currently, the fields, types and defaults used to define a typing.NamedTuple need to be retrieved from three different attributes: _fields, _field_types, and _field_defaults (the first two are combined in __annotations__, but that still misses the defaults).
However, there is a place where all this information can be naturally combined: in the Signature of the constructor (as returned by inspect.signature(cls)). Currently, the Parameter objects in the signature have the information about the parameter names and defaults, but their annotation is not set.
Thus, I would like to propose setting the annotation of the Parameters in the Signature object as well.
This looks like a reasonable idea, if it is possible to implement this without complications. Would you like to submit a PR at https://github.com/python/typing ?
(We have a separate upstream repo for typing while it is provisional.)
I'll just repost the issue there for now (python/typing#454). May work on a patch at some point (looks relatively simple) but no guarantees, so if someone else wants to take over feel free to do so.
Activity
anntzer commentedon Jul 24, 2017
Currently, the fields, types and defaults used to define a typing.NamedTuple need to be retrieved from three different attributes:
_fields,_field_types, and_field_defaults(the first two are combined in__annotations__, but that still misses the defaults).However, there is a place where all this information can be naturally combined: in the Signature of the constructor (as returned by
inspect.signature(cls)). Currently, the Parameter objects in the signature have the information about the parameter names and defaults, but their annotation is not set.Thus, I would like to propose setting the annotation of the Parameters in the Signature object as well.
ilevkivskyi commentedon Jul 28, 2017
This looks like a reasonable idea, if it is possible to implement this without complications. Would you like to submit a PR at https://github.com/python/typing ?
(We have a separate upstream repo for typing while it is provisional.)
anntzer commentedon Jul 28, 2017
I'll just repost the issue there for now (python/typing#454). May work on a patch at some point (looks relatively simple) but no guarantees, so if someone else wants to take over feel free to do so.
isidentical commentedon Jun 3, 2019
IMHO this issue can be closed with this commit (python/typing@435b294)
ilevkivskyi commentedon Jun 3, 2019
Thanks! It looks like this was fixed in typing and then forward ported to CPython.