This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: typing.NamedTuple should add annotations to its constructor (__new__) parameters.
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: BTaskaya, levkivskyi
Priority: normal Keywords:

Created on 2017-07-24 09:07 by Antony.Lee, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (5)
msg298937 - (view) Author: Antony Lee (Antony.Lee) * Date: 2017-07-24 09:07
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.
msg299413 - (view) Author: Ivan Levkivskyi (levkivskyi) * (Python committer) Date: 2017-07-28 17:32
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.)
msg299433 - (view) Author: Antony Lee (Antony.Lee) * Date: 2017-07-28 19:54
I'll just repost the issue there for now (https://github.com/python/typing/issues/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.
msg344390 - (view) Author: Batuhan Taskaya (BTaskaya) * (Python committer) Date: 2019-06-03 08:08
IMHO this issue can be closed with this commit (https://github.com/python/typing/commit/435b29470c7d3e87055531f65681bee9746ab999)
msg344496 - (view) Author: Ivan Levkivskyi (levkivskyi) * (Python committer) Date: 2019-06-03 23:46
Thanks! It looks like this was fixed in typing and then forward ported to CPython.
History
Date User Action Args
2022-04-11 14:58:49adminsetgithub: 75189
2019-06-04 10:00:03Antony.Leesetnosy: - Antony.Lee
2019-06-03 23:46:42levkivskyisetstatus: open -> closed
resolution: fixed
messages: + msg344496

stage: needs patch -> resolved
2019-06-03 08:08:03BTaskayasetnosy: + BTaskaya
messages: + msg344390
2017-07-28 19:54:40Antony.Leesetmessages: + msg299433
2017-07-28 17:32:26levkivskyisetnosy: + levkivskyi
messages: + msg299413

type: enhancement
stage: needs patch
2017-07-24 09:07:47Antony.Leecreate