This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author gvanrossum
Recipients BTaskaya, ethan smith, glyph, gvanrossum, mental, ryansobol
Date 2020-11-12.04:15:28
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1605154528.14.0.198852137408.issue41987@roundup.psfhosted.org>
In-reply-to
Content
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
History
Date User Action Args
2020-11-12 04:15:28gvanrossumsetrecipients: + gvanrossum, glyph, ethan smith, BTaskaya, mental, ryansobol
2020-11-12 04:15:28gvanrossumsetmessageid: <1605154528.14.0.198852137408.issue41987@roundup.psfhosted.org>
2020-11-12 04:15:28gvanrossumlinkissue41987 messages
2020-11-12 04:15:28gvanrossumcreate