[issue37782] typing.NamedTuple default parameter type issue

2019-08-07 Thread Eric V. Smith


Eric V. Smith  added the comment:

example_text is not a field, since you're not giving it a type. It's just a 
normal class member.

The only field in the NamedTuple is example_int. You can't specify any other 
field in the call to MyTestedTuple().

To see this, help(MyTestedTuple) starts with:

class MyTestedTuple(builtins.tuple)
 |  MyTestedTuple(example_int: int = 3)

--
nosy: +eric.smith
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37782] typing.NamedTuple default parameter type issue

2019-08-07 Thread PBrudny


New submission from PBrudny :

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 
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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com