Message352579
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. |
|
Date |
User |
Action |
Args |
2019-09-16 19:59:55 | gribbg | set | recipients:
+ gribbg |
2019-09-16 19:59:55 | gribbg | set | messageid: <1568663995.81.0.542051193907.issue38191@roundup.psfhosted.org> |
2019-09-16 19:59:55 | gribbg | link | issue38191 messages |
2019-09-16 19:59:55 | gribbg | create | |
|