◐ Shell
clean mode source ↗

Message 380803 - Python tracker

FWIW here's a minimal demo:

from __future__ import annotations
from typing import get_type_hints

class C:
    def func(self, a: "C"):
        pass

    print(get_type_hints(func))

In 3.8 this prints

{'a': ForwardRef('C')}

while in 3.9 it raises NameError:

Traceback (most recent call last):
  File "C:\Users\gvanrossum\cpython\t.py", line 4, in <module>
    class C:
  File "C:\Users\gvanrossum\cpython\t.py", line 8, in C
    print(get_type_hints(func))
  File "C:\Python39\lib\typing.py", line 1386, in get_type_hints
    value = _eval_type(value, globalns, localns)
  File "C:\Python39\lib\typing.py", line 254, in _eval_type
    return t._evaluate(globalns, localns, recursive_guard)
  File "C:\Python39\lib\typing.py", line 497, in _evaluate
    self.__forward_value__ = _eval_type(
  File "C:\Python39\lib\typing.py", line 254, in _eval_type
    return t._evaluate(globalns, localns, recursive_guard)
  File "C:\Python39\lib\typing.py", line 493, in _evaluate
    eval(self.__forward_code__, globalns, localns),
  File "<string>", line 1, in <module>
NameError: name 'C' is not defined