@@ -209,11 +209,6 @@ def __init__(
209209 self .allow_tuple_literal = allow_tuple_literal
210210 # Positive if we are analyzing arguments of another (outer) type
211211 self .nesting_level = 0
212- # Should we allow new type syntax when targeting older Python versions
213- # like 'list[int]' or 'X | Y' (allowed in stubs and with `__future__` import)?
214- self .always_allow_new_syntax = self .api .is_stub_file or self .api .is_future_flag_set (
215- "annotations"
216- )
217212 # Should we accept unbound type variables? This is currently used for class bases,
218213 # and alias right hand sides (before they are analyzed as type aliases).
219214 self .allow_unbound_tvars = allow_unbound_tvars
@@ -297,7 +292,7 @@ def visit_unbound_type_nonoptional(self, t: UnboundType, defining_literal: bool)
297292 if (
298293 fullname in get_nongen_builtins (self .options .python_version )
299294 and t .args
300- and not self .always_allow_new_syntax
295+ and not self .api . always_allow_new_syntax
301296 ):
302297 self .fail (
303298 no_subscript_builtin_alias (fullname , propose_alt = not self .defining_alias ), t
@@ -514,10 +509,7 @@ def try_analyze_special_unbound_type(self, t: UnboundType, fullname: str) -> Typ
514509 code = codes .VALID_TYPE ,
515510 )
516511 return AnyType (TypeOfAny .from_error )
517- elif fullname == "typing.Tuple" or (
518- fullname == "builtins.tuple"
519- and (self .always_allow_new_syntax or self .options .python_version >= (3 , 9 ))
520- ):
512+ elif self .api .check_pep585_name (fullname , "tuple" ):
521513 # Tuple is special because it is involved in builtin import cycle
522514 # and may be not ready when used.
523515 sym = self .api .lookup_fully_qualified_or_none ("builtins.tuple" )
@@ -550,10 +542,7 @@ def try_analyze_special_unbound_type(self, t: UnboundType, fullname: str) -> Typ
550542 return make_optional_type (item )
551543 elif fullname == "typing.Callable" :
552544 return self .analyze_callable_type (t )
553- elif fullname == "typing.Type" or (
554- fullname == "builtins.type"
555- and (self .always_allow_new_syntax or self .options .python_version >= (3 , 9 ))
556- ):
545+ elif self .api .check_pep585_name (fullname , "type" ):
557546 if len (t .args ) == 0 :
558547 if fullname == "typing.Type" :
559548 any_type = self .get_omitted_any (t )
@@ -1103,7 +1092,7 @@ def visit_union_type(self, t: UnionType) -> Type:
11031092 if (
11041093 t .uses_pep604_syntax is True
11051094 and t .is_evaluated is True
1106- and not self .always_allow_new_syntax
1095+ and not self .api . always_allow_new_syntax
11071096 and not self .options .python_version >= (3 , 10 )
11081097 ):
11091098 self .fail ("X | Y syntax for unions requires Python 3.10" , t , code = codes .SYNTAX )
0 commit comments