[New-bugs-announce] [issue33075] typing.NamedTuple does not deduce Optional[] from using None as default field value

Vlad Shcherbina report at bugs.python.org
Wed Mar 14 09:25:09 EDT 2018


New submission from Vlad Shcherbina <vlad.shcherbina at gmail.com>:

from typing import *

def f(arg: str = None):
    pass
print(get_type_hints(f))

# {'arg': typing.Union[str, NoneType]}
# as expected


class T(NamedTuple):
    field: str = None
print(get_type_hints(T))

# {'field': <class 'str'>}
# but it should be
# {'field': typing.Union[str, NoneType]}
# for consistency

----------
components: Library (Lib)
messages: 313819
nosy: vlad
priority: normal
severity: normal
status: open
title: typing.NamedTuple does not deduce Optional[] from using None as default field value
type: behavior
versions: Python 3.6, Python 3.7

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


More information about the New-bugs-announce mailing list