[New-bugs-announce] [issue42881] Should typing.get_type_hints change None annotations?

Larry Hastings report at bugs.python.org
Sun Jan 10 06:29:52 EST 2021


New submission from Larry Hastings <larry at hastings.org>:

PEP 484 says:

    (Note that the return type of __init__ ought to be annotated
     with -> None. The reason for this is subtle. [...]

    https://www.python.org/dev/peps/pep-0484/#the-meaning-of-annotations

If you follow this advice, then call typing.get_type_hints() on your __init__ function, you'll find it has turned "None" into "type(None)".

git blame suggests get_type_hints' behavior was in the initial checkin of typing.py (46dbb7d1032c19163f37785509b8f5b3004416e8).  So it's always behaved this way.

Is "None" still considered the correct return annotation of an __init__?  If so, should typing.get_type_hints() really be changing it to type(None)?

----------
components: Library (Lib)
messages: 384760
nosy: eric.smith, gvanrossum, larry
priority: low
severity: normal
stage: test needed
status: open
title: Should typing.get_type_hints change None annotations?
type: behavior
versions: Python 3.10

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


More information about the New-bugs-announce mailing list