@@ -183,15 +183,19 @@ def object_build_class(
183
183
return _base_class_object_build (node , member , basenames , localname = localname )
184
184
185
185
186
- def object_build_function (
187
- node : nodes .Module | nodes .ClassDef , member : _FunctionTypes , localname : str
188
- ) -> None :
189
- """create astroid for a living function object"""
186
+ def _get_args_info_from_callable (
187
+ member : _FunctionTypes ,
188
+ ) -> tuple [list [str ], list [Any ], list [str ], list [str ]]:
189
+ """Returns args, posonlyargs, defaults, kwonlyargs.
190
+
191
+ :note: currently ignores the return annotation.
192
+ """
190
193
signature = inspect .signature (member )
191
194
args : list [str ] = []
192
195
defaults : list [Any ] = []
193
196
posonlyargs : list [str ] = []
194
197
kwonlyargs : list [str ] = []
198
+
195
199
for param_name , param in signature .parameters .items ():
196
200
if param .kind == inspect .Parameter .POSITIONAL_ONLY :
197
201
posonlyargs .append (param_name )
@@ -205,13 +209,25 @@ def object_build_function(
205
209
kwonlyargs .append (param_name )
206
210
if param .default is not inspect ._empty :
207
211
defaults .append (param .default )
212
+
213
+ return args , posonlyargs , defaults , kwonlyargs
214
+
215
+
216
+ def object_build_function (
217
+ node : nodes .Module | nodes .ClassDef , member : _FunctionTypes , localname : str
218
+ ) -> None :
219
+ """create astroid for a living function object"""
220
+ args , posonlyargs , defaults , kwonlyargs = _get_args_info_from_callable (member )
221
+
208
222
func = build_function (
209
223
getattr (member , "__name__" , None ) or localname ,
210
224
args ,
211
225
posonlyargs ,
212
226
defaults ,
213
227
member .__doc__ ,
228
+ kwonlyargs = kwonlyargs ,
214
229
)
230
+
215
231
node .add_local_node (func , localname )
216
232
217
233
0 commit comments