Author PBrudny
Recipients PBrudny
Date 2019-08-07.09:32:12
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1565170333.28.0.690764361146.issue37782@roundup.psfhosted.org>
In-reply-to
Content
There is an issue when NamedTuple parameter with default, which has not explicitly declared type is changed by keyword. Is that an expected behavior (no info https://docs.python.org/3.7/library/collections.html#collections.namedtuple)

Used python release:
Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 23:09:28) [MSC v.1916 64 bit (AMD64)] on win32

test.py:

from typing import NamedTuple


class MyTestedTuple(NamedTuple):
    example_text = "default_text"
    example_int: int = 3


if __name__ == '__main__':
    print(MyTestedTuple().example_text)
    fault_tuple = MyTestedTuple(example_text="text_from_call")
    print(fault_tuple.example_text)

Call:

python test.py

default_text

Traceback (most recent call last):
  File "test.py", line 11, in <module>
    fault_tuple = MyTestedTuple(example_text="text_from_call")
TypeError: __new__() got an unexpected keyword argument 'example_text'
History
Date User Action Args
2019-08-07 09:32:13PBrudnysetrecipients: + PBrudny
2019-08-07 09:32:13PBrudnysetmessageid: <1565170333.28.0.690764361146.issue37782@roundup.psfhosted.org>
2019-08-07 09:32:13PBrudnylinkissue37782 messages
2019-08-07 09:32:12PBrudnycreate