@@ -357,38 +357,46 @@ class ListSchema(SchemaData):
357
357
358
358
@override
359
359
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 ()} ]"
361
361
if include_constraints and (args := self ._get_field_args ()):
362
362
return f"Annotated[{ type_string } , { self ._get_field_string (args )} ]"
363
363
return type_string
364
364
365
365
@override
366
366
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 ()} ]"
368
372
369
373
@override
370
374
def get_model_imports (self ) -> set [str ]:
371
375
imports = super ().get_model_imports ()
372
376
imports .add ("from githubkit.compat import PYDANTIC_V2" )
377
+ imports .add ("import builtins" )
373
378
imports .update (self .item_schema .get_model_imports ())
374
379
return imports
375
380
376
381
@override
377
382
def get_type_imports (self ) -> set [str ]:
378
383
imports = super ().get_type_imports ()
384
+ imports .add ("import builtins" )
379
385
imports .update (self .item_schema .get_type_imports ())
380
386
return imports
381
387
382
388
@override
383
389
def get_param_imports (self ) -> set [str ]:
384
390
imports = super ().get_param_imports ()
391
+ imports .add ("import builtins" )
385
392
imports .update (self .item_schema .get_param_imports ())
386
393
return imports
387
394
388
395
@override
389
396
def get_using_imports (self ) -> set [str ]:
390
397
imports = super ().get_using_imports ()
391
398
imports .add ("from githubkit.compat import PYDANTIC_V2" )
399
+ imports .add ("import builtins" )
392
400
imports .update (self .item_schema .get_using_imports ())
393
401
return imports
394
402
0 commit comments