File tree Expand file tree Collapse file tree 5 files changed +63
-1
lines changed
client_generators/input_types_generator Expand file tree Collapse file tree 5 files changed +63
-1
lines changed Original file line number Diff line number Diff line change 11import ast
2+ import builtins
23import re
34from keyword import iskeyword
45from textwrap import indent
1718]
1819
1920
21+ def _is_builtin_type_name (name : str ) -> bool :
22+ try :
23+ value = getattr (builtins , name )
24+ except AttributeError :
25+ return False
26+ return isinstance (value , type )
27+
28+
2029def ast_to_str (
2130 ast_obj : ast .AST ,
2231 remove_unused_imports : bool = True ,
@@ -124,7 +133,7 @@ def process_name(
124133 processed_name = name
125134 if convert_to_snake_case :
126135 processed_name = str_to_snake_case (processed_name )
127- if iskeyword (processed_name ):
136+ if iskeyword (processed_name ) or _is_builtin_type_name ( processed_name ) :
128137 processed_name += "_"
129138 if (
130139 handle_pydantic_resrved_field_names
Original file line number Diff line number Diff line change @@ -197,3 +197,34 @@ def test_generate_returns_module_with_valid_field_names():
197197 "underscore_named_field_" ,
198198 "schema_" ,
199199 }
200+
201+
202+ def test_generate_returns_module_with_builtin_field_names ():
203+ schema = """
204+ input BuiltinsInput {
205+ list: [Int!]
206+ dict: String
207+ set: Boolean
208+ tuple: Float
209+ int: Int
210+ str: String
211+ bool: Boolean
212+ }
213+ """
214+
215+ generator = InputTypesGenerator (schema = build_ast_schema (parse (schema )))
216+
217+ module = generator .generate ()
218+
219+ parsed = ast .parse (ast_to_str (module ))
220+ class_def = get_class_def (parsed )
221+ field_names = get_assignment_target_names (class_def )
222+ assert field_names == {
223+ "list_" ,
224+ "dict_" ,
225+ "set_" ,
226+ "tuple_" ,
227+ "int_" ,
228+ "str_" ,
229+ "bool_" ,
230+ }
Original file line number Diff line number Diff line change 1313from .fragments import BasicUser , UserPersonalData
1414from .get_users_counter import GetUsersCounter
1515from .input_types import (
16+ BuiltinsInput ,
1617 LocationInput ,
1718 NotificationsPreferencesInput ,
1819 UserCreateInput ,
2627 "AsyncBaseClient" ,
2728 "BaseModel" ,
2829 "BasicUser" ,
30+ "BuiltinsInput" ,
2931 "Client" ,
3032 "Color" ,
3133 "CreateUser" ,
Original file line number Diff line number Diff line change @@ -48,5 +48,15 @@ class NotificationsPreferencesInput(BaseModel):
4848 title : str
4949
5050
51+ class BuiltinsInput (BaseModel ):
52+ list_ : Optional [list [int ]] = Field (alias = "list" , default = None )
53+ dict_ : Optional [str ] = Field (alias = "dict" , default = None )
54+ set_ : Optional [bool ] = Field (alias = "set" , default = None )
55+ tuple_ : Optional [float ] = Field (alias = "tuple" , default = None )
56+ int_ : Optional [int ] = Field (alias = "int" , default = None )
57+ str_ : Optional [str ] = Field (alias = "str" , default = None )
58+ bool_ : Optional [bool ] = Field (alias = "bool" , default = None )
59+
60+
5161UserCreateInput .model_rebuild ()
5262UserPreferencesInput .model_rebuild ()
Original file line number Diff line number Diff line change @@ -75,3 +75,13 @@ input NotificationsPreferencesInput {
7575 receiveSms : Boolean !
7676 title : String !
7777}
78+
79+ input BuiltinsInput {
80+ list : [Int ! ]
81+ dict : String
82+ set : Boolean
83+ tuple : Float
84+ int : Int
85+ str : String
86+ bool : Boolean
87+ }
You can’t perform that action at this time.
0 commit comments