[New-bugs-announce] [issue37782] typing.NamedTuple default parameter type issue

PBrudny report at bugs.python.org
Wed Aug 7 05:32:13 EDT 2019


New submission from PBrudny <przedirty at gmail.com>:

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'

----------
components: Library (Lib)
files: test.py
messages: 349157
nosy: PBrudny
priority: normal
severity: normal
status: open
title: typing.NamedTuple default parameter type issue
type: behavior
versions: Python 3.7
Added file: https://bugs.python.org/file48533/test.py

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37782>
_______________________________________


More information about the New-bugs-announce mailing list