(func: str, f: Callable)
| 264 | |
| 265 | |
| 266 | def getfuncprops(func: str, f: Callable) -> FuncProps | None: |
| 267 | # Check if it's a real bound method or if it's implicitly calling __init__ |
| 268 | # (i.e. FooClass(...) and not FooClass.__init__(...) -- the former would |
| 269 | # not take 'self', the latter would: |
| 270 | try: |
| 271 | func_name = getattr(f, "__name__", None) |
| 272 | except: |
| 273 | # if calling foo.__name__ would result in an error |
| 274 | func_name = None |
| 275 | |
| 276 | try: |
| 277 | is_bound_method = ( |
| 278 | (inspect.ismethod(f) and f.__self__ is not None) |
| 279 | or (func_name == "__init__" and not func.endswith(".__init__")) |
| 280 | or (func_name == "__new__" and not func.endswith(".__new__")) |
| 281 | ) |
| 282 | except: |
| 283 | # if f is a method from a xmlrpclib.Server instance, func_name == |
| 284 | # '__init__' throws xmlrpclib.Fault (see #202) |
| 285 | return None |
| 286 | try: |
| 287 | argspec = _get_argspec_from_signature(f) |
| 288 | try: |
| 289 | argspec = _fix_default_values(f, argspec) |
| 290 | except KeyError as ex: |
| 291 | # Parsing of the source failed. If f has a __signature__, we trust it. |
| 292 | if not hasattr(f, "__signature__"): |
| 293 | raise ex |
| 294 | fprops = FuncProps(func, argspec, is_bound_method) |
| 295 | except (TypeError, KeyError, ValueError): |
| 296 | argspec_pydoc = _getpydocspec(f) |
| 297 | if argspec_pydoc is None: |
| 298 | return None |
| 299 | if inspect.ismethoddescriptor(f): |
| 300 | argspec_pydoc.args.insert(0, "obj") |
| 301 | fprops = FuncProps(func, argspec_pydoc, is_bound_method) |
| 302 | return fprops |
| 303 | |
| 304 | |
| 305 | def is_eval_safe_name(string: str) -> bool: |
nothing calls this directly
no test coverage detected