@@ -357,38 +357,46 @@ class ListSchema(SchemaData):
357357
358358 @override
359359 def get_type_string (self , include_constraints : bool = True ) -> str :
360- type_string = f"list[{ self .item_schema .get_type_string ()} ]"
360+ type_string = f"builtins. list[{ self .item_schema .get_type_string ()} ]"
361361 if include_constraints and (args := self ._get_field_args ()):
362362 return f"Annotated[{ type_string } , { self ._get_field_string (args )} ]"
363363 return type_string
364364
365365 @override
366366 def get_param_type_string (self ) -> str :
367- return f"list[{ self .item_schema .get_param_type_string ()} ]"
367+ # We **must** refer to `builtins.list` here explicitly to avoid shadowing:
368+ # class A:
369+ # def list(self): ...
370+ # def meth(self) -> list[int]: ... # Oops, it's the `list` method, bad hint
371+ return f"builtins.list[{ self .item_schema .get_param_type_string ()} ]"
368372
369373 @override
370374 def get_model_imports (self ) -> set [str ]:
371375 imports = super ().get_model_imports ()
372376 imports .add ("from githubkit.compat import PYDANTIC_V2" )
377+ imports .add ("import builtins" )
373378 imports .update (self .item_schema .get_model_imports ())
374379 return imports
375380
376381 @override
377382 def get_type_imports (self ) -> set [str ]:
378383 imports = super ().get_type_imports ()
384+ imports .add ("import builtins" )
379385 imports .update (self .item_schema .get_type_imports ())
380386 return imports
381387
382388 @override
383389 def get_param_imports (self ) -> set [str ]:
384390 imports = super ().get_param_imports ()
391+ imports .add ("import builtins" )
385392 imports .update (self .item_schema .get_param_imports ())
386393 return imports
387394
388395 @override
389396 def get_using_imports (self ) -> set [str ]:
390397 imports = super ().get_using_imports ()
391398 imports .add ("from githubkit.compat import PYDANTIC_V2" )
399+ imports .add ("import builtins" )
392400 imports .update (self .item_schema .get_using_imports ())
393401 return imports
394402
0 commit comments