-
Notifications
You must be signed in to change notification settings - Fork 225
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
Annotating namedtuples item types #21
Comments
This reads to me more like an annotation for a normal tuple -- I would expect that something with type
This would also help out tools like jython and reticulated that currently are unequipped to parse comment typings. |
The problem is that dicts are unordered, while namedtuple requires the On Thu, Nov 6, 2014 at 4:14 PM, Michael Vitousek notifications@github.com
--Guido van Rossum (python.org/~guido) |
Ah, right, of course. The same principle could still work with
perhaps. |
Maybe we should call it Another syntax idea: X = NamedTuple('X', [('a', int), ('b', str)]) This syntax is arguably more readable if the tuple has many items, as it's obvious which types map to which items. |
+1 on both points.
|
I've started implementing my last idea ( |
Typing namedtuples is a good idea. |
Jukka has just implemented this for mypy. See (Hm, we have too many repos with issue trackers where we have these On Tue, Jan 6, 2015 at 11:58 PM, Łukasz Langa notifications@github.com
--Guido van Rossum (python.org/~guido) |
Agreed to keep discussions in one place. Context-switching between the repos slows us down. |
This is also implemented in my typing.py. |
I'm late to this discussion...but, wasn't there recently a discussion on making |
Yes, but that's a big if -- I don't know who's actually working on that. If dicts become ordered we can support that -- but even so, I'd like to support the list-of-tuples form for compatibility with Python 3.2-3.4. |
Closing, it's now also described in the PEP. |
Oops. |
There should be a way of annotating the item types of named tuples. Here is my suggested syntax:
The type of
a
would beint
and the type ofb
would bestr
.The text was updated successfully, but these errors were encountered: