ID EN
Inspect

signature

Python 3.11

Return a Signature object for the given callable:

Syntax

PYTHON
inspect.signature(callable, *, follow_wrapped=True, globals=None, locals=None, eval_str=False)

Examples

Example 1
PYTHON
>>> from inspect import signature
>>> def foo(a, *, b:int, **kwargs):
...     pass

>>> sig = signature(foo)

>>> str(sig)
'(a, *, b: int, **kwargs)'

>>> str(sig.parameters['b'])
'b: int'

>>> sig.parameters['b'].annotation
<class 'int'>

See Also

Signature functools.partial() signature() get_annotations() get_annotations() get_annotations() ValueError TypeError