Skip to content

typing.NamedTuple should add annotations to its constructor (__new__) parameters. #75189

Closed

Description

@anntzer
mannequin
BPO 31006
Nosy @ilevkivskyi, @isidentical

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 = None
closed_at = <Date 2019-06-03.23:46:42.059>
created_at = <Date 2017-07-24.09:07:47.250>
labels = ['type-feature', 'library']
title = 'typing.NamedTuple should add annotations to its constructor (__new__) parameters.'
updated_at = <Date 2019-06-04.10:00:03.368>
user = 'https://github.com/anntzer'

bugs.python.org fields:

activity = <Date 2019-06-04.10:00:03.368>
actor = 'Antony.Lee'
assignee = 'none'
closed = True
closed_date = <Date 2019-06-03.23:46:42.059>
closer = 'levkivskyi'
components = ['Library (Lib)']
creation = <Date 2017-07-24.09:07:47.250>
creator = 'Antony.Lee'
dependencies = []
files = []
hgrepos = []
issue_num = 31006
keywords = []
message_count = 5.0
messages = ['298937', '299413', '299433', '344390', '344496']
nosy_count = 2.0
nosy_names = ['levkivskyi', 'BTaskaya']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue31006'
versions = ['Python 3.6']

Activity

  1. anntzer commented on Jul 24, 2017

    anntzermannequin
    MannequinAuthor

    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.

  2. added
    stdlib
    on Jul 24, 2017
  3. ilevkivskyi commented on Jul 28, 2017

    @ilevkivskyi
    Member

    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.)

  4. added
    type-feature
    on Jul 28, 2017
  5. anntzer commented on Jul 28, 2017

    anntzermannequin
    MannequinAuthor

    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.

  6. isidentical commented on Jun 3, 2019

    @isidentical
    SponsorMember

    IMHO this issue can be closed with this commit (python/typing@435b294)

  7. ilevkivskyi commented on Jun 3, 2019

    @ilevkivskyi
    Member

    Thanks! It looks like this was fixed in typing and then forward ported to CPython.

  8. transferred this issue fromon Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibtype-feature

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions