Skip to content
14 changes: 7 additions & 7 deletions conformance/tests/annotations_forward_refs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


import types
from typing import assert_type
from typing import assert_type, Any


def func1(
Expand Down Expand Up @@ -59,7 +59,7 @@ def invalid_annotations(

# > It should evaluate without errors once the module has been fully loaded.
# > The local and global namespace in which it is evaluated should be the same
# > namespaces in which default arguments to the same function would be evaluated.
# > namespaces in which normal non-string types would be evaluated.


class ClassB:
Expand All @@ -79,21 +79,21 @@ class ClassD:

ClassF: "ClassF" # E: circular reference

str: "str" = "" # OK
str: "str" = "" # E: circular reference

def int(self) -> None: # OK
...

x: "int" = 0 # OK

y: int = 0 # E: Refers to local int, which isn't a legal type expression

x: "int" = 0 # # E: Refers to a local int as well

def __init__(self) -> None:
self.ClassC = ClassC()


assert_type(ClassD.str, str)
assert_type(ClassD.x, int)
assert_type(ClassD.str, Any)
assert_type(ClassD.x, Any)


# > If a triple quote is used, the string should be parsed as though it is implicitly
Expand Down
3 changes: 1 addition & 2 deletions docs/spec/annotations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,7 @@ The string literal should contain a valid Python expression (i.e.,
``compile(lit, '', 'eval')`` should be a valid code object) and it
should evaluate without errors once the module has been fully loaded.
The local and global namespace in which it is evaluated should be the
same namespaces in which default arguments to the same function would
be evaluated.
same namespaces in which normal non-string types would be evaluated.

Moreover, the expression should be parseable as a valid type hint, i.e.,
it is constrained by the rules from :ref:`the expression grammar <expression-grammar>`.
Expand Down