@@ -297,43 +297,40 @@ def not_declared_in_type_params(self, tvar_name: str) -> bool:
297297 and tvar_name not in self .alias_type_params_names
298298 )
299299
300- def handle_placeholder_node (self , node : PlaceholderNode , t : UnboundType ) -> Type :
301- if node .becomes_typeinfo :
302- # Reference to placeholder type.
303- if self .api .final_iteration :
304- self .cannot_resolve_type (t )
305- return AnyType (TypeOfAny .from_error )
306- elif self .allow_placeholder :
307- self .api .defer ()
308- else :
309- self .api .record_incomplete_ref ()
310- # Always allow ParamSpec for placeholders, if they are actually not valid,
311- # they will be reported later, after we resolve placeholders.
312- return PlaceholderType (
313- node .fullname ,
314- self .anal_array (
315- t .args ,
316- allow_param_spec = True ,
317- allow_param_spec_literals = True ,
318- allow_unpack = True ,
319- ),
320- t .line ,
321- )
322- else :
323- if self .api .final_iteration :
324- self .cannot_resolve_type (t )
325- return AnyType (TypeOfAny .from_error )
326- else :
327- # Reference to an unknown placeholder node.
328- self .api .record_incomplete_ref ()
329- return AnyType (TypeOfAny .special_form )
330-
331300 def visit_unbound_type_nonoptional (self , t : UnboundType , defining_literal : bool ) -> Type :
332301 sym = self .lookup_qualified (t .name , t )
333302 if sym is not None :
334303 node = sym .node
335304 if isinstance (node , PlaceholderNode ):
336- return self .handle_placeholder_node (node , t )
305+ if node .becomes_typeinfo :
306+ # Reference to placeholder type.
307+ if self .api .final_iteration :
308+ self .cannot_resolve_type (t )
309+ return AnyType (TypeOfAny .from_error )
310+ elif self .allow_placeholder :
311+ self .api .defer ()
312+ else :
313+ self .api .record_incomplete_ref ()
314+ # Always allow ParamSpec for placeholders, if they are actually not valid,
315+ # they will be reported later, after we resolve placeholders.
316+ return PlaceholderType (
317+ node .fullname ,
318+ self .anal_array (
319+ t .args ,
320+ allow_param_spec = True ,
321+ allow_param_spec_literals = True ,
322+ allow_unpack = True ,
323+ ),
324+ t .line ,
325+ )
326+ else :
327+ if self .api .final_iteration :
328+ self .cannot_resolve_type (t )
329+ return AnyType (TypeOfAny .from_error )
330+ else :
331+ # Reference to an unknown placeholder node.
332+ self .api .record_incomplete_ref ()
333+ return AnyType (TypeOfAny .special_form )
337334 if node is None :
338335 self .fail (f"Internal error (node is None, kind={ sym .kind } )" , t )
339336 return AnyType (TypeOfAny .special_form )
@@ -1705,9 +1702,14 @@ def analyze_literal_param(self, idx: int, arg: Type, ctx: Context) -> list[Type]
17051702 return None
17061703
17071704 # Make sure the literal's class is ready
1708- sym = self .lookup_fully_qualified (arg .base_type_name )
1709- if isinstance (sym .node , PlaceholderNode ):
1710- return [self .handle_placeholder_node (sym .node , UnboundType (arg .base_type_name ))]
1705+ sym = self .api .lookup_fully_qualified_or_none (arg .base_type_name )
1706+ if sym is None or isinstance (sym .node , PlaceholderNode ):
1707+ assert arg .base_type_name .startswith ("builtins." )
1708+ if self .api .is_incomplete_namespace ("builtins" ):
1709+ self .api .record_incomplete_ref ()
1710+ else :
1711+ self .fail (f'Name "{ arg .base_type_name } " is not defined' , arg )
1712+ return [AnyType (TypeOfAny .special_form )]
17111713
17121714 # Remap bytes and unicode into the appropriate type for the correct Python version
17131715 fallback = self .named_type (arg .base_type_name )
0 commit comments