(self, func: object, ctx: FunctionContext)
| 268 | ) |
| 269 | |
| 270 | def get_default_function_sig(self, func: object, ctx: FunctionContext) -> FunctionSig: |
| 271 | argspec = None |
| 272 | if not self.is_c_module: |
| 273 | # Get the full argument specification of the function |
| 274 | try: |
| 275 | argspec = inspect.getfullargspec(func) |
| 276 | except TypeError: |
| 277 | # some callables cannot be inspected, e.g. functools.partial |
| 278 | pass |
| 279 | if argspec is None: |
| 280 | if ctx.class_info is not None: |
| 281 | # method: |
| 282 | return FunctionSig( |
| 283 | name=ctx.name, |
| 284 | args=infer_c_method_args(ctx.name, ctx.class_info.self_var), |
| 285 | ret_type=infer_method_ret_type(ctx.name), |
| 286 | ) |
| 287 | else: |
| 288 | # function: |
| 289 | return FunctionSig( |
| 290 | name=ctx.name, |
| 291 | args=[ArgSig(name="*args"), ArgSig(name="**kwargs")], |
| 292 | ret_type=None, |
| 293 | ) |
| 294 | |
| 295 | # Extract the function arguments, defaults, and varargs |
| 296 | args = argspec.args |
| 297 | defaults = argspec.defaults |
| 298 | varargs = argspec.varargs |
| 299 | kwargs = argspec.varkw |
| 300 | annotations = argspec.annotations |
| 301 | kwonlyargs = argspec.kwonlyargs |
| 302 | kwonlydefaults = argspec.kwonlydefaults |
| 303 | |
| 304 | def get_annotation(key: str) -> str | None: |
| 305 | if key not in annotations: |
| 306 | return None |
| 307 | argtype = annotations[key] |
| 308 | if argtype is None: |
| 309 | return "None" |
| 310 | if not isinstance(argtype, str): |
| 311 | return self.get_type_fullname(argtype) |
| 312 | return argtype |
| 313 | |
| 314 | arglist: list[ArgSig] = [] |
| 315 | |
| 316 | # Add the arguments to the signature |
| 317 | def add_args( |
| 318 | args: list[str], get_default_value: Callable[[int, str], object | _Missing] |
| 319 | ) -> None: |
| 320 | for i, arg in enumerate(args): |
| 321 | # Check if the argument has a default value |
| 322 | default_value = get_default_value(i, arg) |
| 323 | if default_value is not _Missing.VALUE: |
| 324 | if arg in annotations: |
| 325 | argtype = get_annotation(arg) |
| 326 | else: |
| 327 | argtype = self.get_type_annotation(default_value) |
no test coverage detected