MCPcopy Index your code
hub / github.com/bpython/bpython / getfuncprops

Function getfuncprops

bpython/inspection.py:266–302  ·  view source on GitHub ↗
(func: str, f: Callable)

Source from the content-addressed store, hash-verified

264
265
266def 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
305def is_eval_safe_name(string: str) -> bool:

Callers

nothing calls this directly

Calls 4

_fix_default_valuesFunction · 0.85
FuncPropsClass · 0.85
_getpydocspecFunction · 0.85

Tested by

no test coverage detected