@@ -976,8 +976,15 @@ class TypeChecker(BaseChecker):
976976 def open (self ) -> None :
977977 py_version = self .linter .config .py_version
978978 self ._py310_plus = py_version >= (3 , 10 )
979+ self ._py314_plus = py_version >= (3 , 14 )
980+ self ._postponed_evaluation_enabled = False
979981 self ._mixin_class_rgx = self .linter .config .mixin_class_rgx
980982
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+
981988 @cached_property
982989 def _compiled_generated_members (self ) -> tuple [Pattern [str ], ...]:
983990 # do this lazily since config not fully initialized in __init__
@@ -1066,7 +1073,7 @@ def visit_attribute(
10661073 ):
10671074 return
10681075
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 (
10701077 node
10711078 ):
10721079 return
@@ -1950,9 +1957,10 @@ def _detect_unsupported_alternative_union_syntax(self, node: nodes.BinOp) -> Non
19501957 if self ._py310_plus : # 310+ supports the new syntax
19511958 return
19521959
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+ ):
19561964 # Use in type annotations only allowed if
19571965 # postponed evaluation is enabled.
19581966 self ._check_unsupported_alternative_union_syntax (node )
@@ -1974,7 +1982,7 @@ def _detect_unsupported_alternative_union_syntax(self, node: nodes.BinOp) -> Non
19741982 # Make sure to filter context if postponed evaluation is enabled
19751983 # and parent is allowed node type.
19761984 allowed_nested_syntax = False
1977- if is_postponed_evaluation_enabled ( node ) :
1985+ if self . _postponed_evaluation_enabled :
19781986 parent_node = node .parent
19791987 while True :
19801988 if isinstance (parent_node , TYPE_ANNOTATION_NODES_TYPES ):
0 commit comments