[New-bugs-announce] [issue34921] NoReturn not allowed by get_type_hints when future import annotations is used

Ismo Toijala report at bugs.python.org
Sun Oct 7 07:46:05 EDT 2018


New submission from Ismo Toijala <ismo.toijala at gmail.com>:

The following example should work but does not.
Note that it does work without the future import.

from __future__ import annotations

import typing

def f() -> typing.NoReturn:
    pass

typing.get_type_hints(f)

Traceback (most recent call last):
  File "foo.py", line 8, in <module>
    typing.get_type_hints(f)
  File "/usr/lib/python3.7/typing.py", line 1001, in get_type_hints
    value = _eval_type(value, globalns, localns)
  File "/usr/lib/python3.7/typing.py", line 260, in _eval_type
    return t._evaluate(globalns, localns)
  File "/usr/lib/python3.7/typing.py", line 466, in _evaluate
    is_argument=self.__forward_is_argument__)
  File "/usr/lib/python3.7/typing.py", line 135, in _type_check
    raise TypeError(f"Plain {arg} is not valid as type argument")
TypeError: Plain typing.NoReturn is not valid as type argument

----------
components: Library (Lib)
messages: 327274
nosy: itoijala
priority: normal
severity: normal
status: open
title: NoReturn not allowed by get_type_hints when future import annotations is used
type: behavior
versions: Python 3.7

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


More information about the New-bugs-announce mailing list