@@ -976,8 +976,15 @@ class TypeChecker(BaseChecker):
976
976
def open (self ) -> None :
977
977
py_version = self .linter .config .py_version
978
978
self ._py310_plus = py_version >= (3 , 10 )
979
+ self ._py314_plus = py_version >= (3 , 14 )
980
+ self ._postponed_evaluation_enabled = False
979
981
self ._mixin_class_rgx = self .linter .config .mixin_class_rgx
980
982
983
+ def visit_module (self , node : nodes .Module ) -> None :
984
+ self ._postponed_evaluation_enabled = (
985
+ self ._py314_plus or is_postponed_evaluation_enabled (node )
986
+ )
987
+
981
988
@cached_property
982
989
def _compiled_generated_members (self ) -> tuple [Pattern [str ], ...]:
983
990
# do this lazily since config not fully initialized in __init__
@@ -1066,7 +1073,7 @@ def visit_attribute(
1066
1073
):
1067
1074
return
1068
1075
1069
- if is_postponed_evaluation_enabled ( node ) and is_node_in_type_annotation_context (
1076
+ if self . _postponed_evaluation_enabled and is_node_in_type_annotation_context (
1070
1077
node
1071
1078
):
1072
1079
return
@@ -1950,9 +1957,10 @@ def _detect_unsupported_alternative_union_syntax(self, node: nodes.BinOp) -> Non
1950
1957
if self ._py310_plus : # 310+ supports the new syntax
1951
1958
return
1952
1959
1953
- if isinstance (
1954
- node .parent , TYPE_ANNOTATION_NODES_TYPES
1955
- ) and not is_postponed_evaluation_enabled (node ):
1960
+ if (
1961
+ isinstance (node .parent , TYPE_ANNOTATION_NODES_TYPES )
1962
+ and not self ._postponed_evaluation_enabled
1963
+ ):
1956
1964
# Use in type annotations only allowed if
1957
1965
# postponed evaluation is enabled.
1958
1966
self ._check_unsupported_alternative_union_syntax (node )
@@ -1974,7 +1982,7 @@ def _detect_unsupported_alternative_union_syntax(self, node: nodes.BinOp) -> Non
1974
1982
# Make sure to filter context if postponed evaluation is enabled
1975
1983
# and parent is allowed node type.
1976
1984
allowed_nested_syntax = False
1977
- if is_postponed_evaluation_enabled ( node ) :
1985
+ if self . _postponed_evaluation_enabled :
1978
1986
parent_node = node .parent
1979
1987
while True :
1980
1988
if isinstance (parent_node , TYPE_ANNOTATION_NODES_TYPES ):
0 commit comments