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.

Author gribbg
Recipients gribbg
Date 2019-09-16.19:59:55
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1568663995.81.0.542051193907.issue38191@roundup.psfhosted.org>
In-reply-to
Content
At present, it is not possible to use the shorthand notation to define a NamedTuple with typename or fields.  I.e., NamedTuple('MyTuple', typename=str, fields=int) does not work.  Changing the parameter names to _typename and _fields would allow any non-private, legal identifier to be used in the shorthand notation.
  
>>> import typing
>>> typing.NamedTuple('Example', fieldz=int)
<class '__main__.Example'>
>>> typing.NamedTuple('Example2', fields=int)
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Program Files\Python37\lib\typing.py", line 1411, in __new__
    return _make_nmtuple(typename, fields)
  File "C:\Program Files\Python37\lib\typing.py", line 1326, in _make_nmtuple
    types = [(n, _type_check(t, msg)) for n, t in types]
TypeError: 'type' object is not iterable


Of course, it is fairly easy to work around the issue by using fields parameter:

>>> typing.NamedTuple('Example3', [('fields', int)])
<class '__main__.Example3'>


There would be backwards compatibility issues with any code using named arguments for fields or typename.
History
Date User Action Args
2019-09-16 19:59:55gribbgsetrecipients: + gribbg
2019-09-16 19:59:55gribbgsetmessageid: <1568663995.81.0.542051193907.issue38191@roundup.psfhosted.org>
2019-09-16 19:59:55gribbglinkissue38191 messages
2019-09-16 19:59:55gribbgcreate