Skip to content

Allow keyword syntax for NamedTuple #302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ilevkivskyi opened this issue Oct 18, 2016 · 1 comment
Closed

Allow keyword syntax for NamedTuple #302

ilevkivskyi opened this issue Oct 18, 2016 · 1 comment

Comments

@ilevkivskyi
Copy link
Member

It was proposed by Guido to add the following syntax:

Point = typing.NamedTuple('Point', x=int, y=int)
p = Point(x=1, y=2)
p.x

I also like it. Probably, we should also support it for TypedDict.

@JukkaL
Copy link
Contributor

JukkaL commented Oct 18, 2016

Seems reasonable, though if NamedTuple already supports keyword arguments, there may be some ambiguity. And this is a Python 3.6+ only feature.

gvanrossum pushed a commit that referenced this issue Nov 13, 2016
Fixes #302
Example:

    Employee = NamedTuple('Employee', name=str, id=int)

Note that this requires 3.6+ since order of kwargs should be preserved.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants