ID EN
Inspect

Signature

Python 3.11

A Signature object represents the call signature of a function and its return annotation. For each parameter accepted by the function it stores a Parameter object in its parameters collection.

Syntax

PYTHON
class inspect.Signature(parameters=None, *, return_annotation=Signature.empty)

Examples

Example 1
PYTHON
>>> def test(a, b):
...     pass
>>> sig = signature(test)
>>> new_sig = sig.replace(return_annotation="new return anno")
>>> str(new_sig)
"(a, b) -> 'new return anno'"
Example 2
PYTHON
class MySignature(Signature):
    pass
sig = MySignature.from_callable(sum)
assert isinstance(sig, MySignature)

See Also

Parameter parameters Parameter Signature.replace() hashable Parameter Signature.empty BoundArguments