MCPcopy Index your code
hub / github.com/RustPython/RustPython / _signature_from_function

Function _signature_from_function

Lib/inspect.py:2307–2401  ·  view source on GitHub ↗

Private helper: constructs Signature for the given python function.

(cls, func, skip_bound_arg=True,
                             globals=None, locals=None, eval_str=False,
                             *, annotation_format=Format.VALUE)

Source from the content-addressed store, hash-verified

2305
2306
2307def _signature_from_function(cls, func, skip_bound_arg=True,
2308 globals=None, locals=None, eval_str=False,
2309 *, annotation_format=Format.VALUE):
2310 """Private helper: constructs Signature for the given python function."""
2311
2312 is_duck_function = False
2313 if not isfunction(func):
2314 if _signature_is_functionlike(func):
2315 is_duck_function = True
2316 else:
2317 # If it's not a pure Python function, and not a duck type
2318 # of pure function:
2319 raise TypeError('{!r} is not a Python function'.format(func))
2320
2321 s = getattr(func, "__text_signature__", None)
2322 if s:
2323 return _signature_fromstr(cls, func, s, skip_bound_arg)
2324
2325 Parameter = cls._parameter_cls
2326
2327 # Parameter information.
2328 func_code = func.__code__
2329 pos_count = func_code.co_argcount
2330 arg_names = func_code.co_varnames
2331 posonly_count = func_code.co_posonlyargcount
2332 positional = arg_names[:pos_count]
2333 keyword_only_count = func_code.co_kwonlyargcount
2334 keyword_only = arg_names[pos_count:pos_count + keyword_only_count]
2335 annotations = get_annotations(func, globals=globals, locals=locals, eval_str=eval_str,
2336 format=annotation_format)
2337 defaults = func.__defaults__
2338 kwdefaults = func.__kwdefaults__
2339
2340 if defaults:
2341 pos_default_count = len(defaults)
2342 else:
2343 pos_default_count = 0
2344
2345 parameters = []
2346
2347 non_default_count = pos_count - pos_default_count
2348 posonly_left = posonly_count
2349
2350 # Non-keyword-only parameters w/o defaults.
2351 for name in positional[:non_default_count]:
2352 kind = _POSITIONAL_ONLY if posonly_left else _POSITIONAL_OR_KEYWORD
2353 annotation = annotations.get(name, _empty)
2354 parameters.append(Parameter(name, annotation=annotation,
2355 kind=kind))
2356 if posonly_left:
2357 posonly_left -= 1
2358
2359 # ... w/ defaults.
2360 for offset, name in enumerate(positional[non_default_count:]):
2361 kind = _POSITIONAL_ONLY if posonly_left else _POSITIONAL_OR_KEYWORD
2362 annotation = annotations.get(name, _empty)
2363 parameters.append(Parameter(name, annotation=annotation,
2364 kind=kind,

Callers 1

_signature_from_callableFunction · 0.85

Calls 12

get_annotationsFunction · 0.90
isfunctionFunction · 0.85
getattrFunction · 0.85
_signature_fromstrFunction · 0.85
lenFunction · 0.85
enumerateFunction · 0.85
ParameterClass · 0.70
clsClass · 0.50
formatMethod · 0.45
getMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected