[issue45972] typing.NamedTuple with default arguments without type annotations is falsy

Erik Montnemery report at bugs.python.org
Fri Dec 3 03:45:38 EST 2021


New submission from Erik Montnemery <erik at montnemery.com>:

typing.NamedTuple behaves in surprising ways when it has default arguments which lack type annotations:

>>> from typing import NamedTuple
>>> class MyTuple(NamedTuple):
...     a = 1000
...
>>> tmp = MyTuple()
>>> tmp.a
1000
>>> len(tmp)
0
>>> bool(tmp)
False

Tested in Python 3.8 and 3.9

----------
messages: 407570
nosy: emontnemery
priority: normal
severity: normal
status: open
title: typing.NamedTuple with default arguments without type annotations is falsy
type: behavior
versions: Python 3.8, Python 3.9

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


More information about the Python-bugs-list mailing list