sigtools is a Python package that enhances introspection capabilities for determining function signatures, especially when decorators modify them. It provides utilities for boosting callable signature introspection, backports keyword-only parameters for older Python versions (though current versions are Python 3+), and tools for combining functions while preserving correct signatures. The current version is 4.0.1, with releases occurring periodically to maintain compatibility and add features.
pip install sigtoolsVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to use `sigtools.signature` to introspect a function and how the `@signature` decorator can be used to explicitly set a function's introspectable signature, making `wrapped_func` appear with the same signature as `original_func`.
Ensure your project runs on Python 3.6 or a more recent version. If Python 2 compatibility is essential, you may need to use an older `sigtools` version (e.g., <2.0) at your own risk, but this is not recommended due to Python 2's end-of-life.
Replace `inspect.signature(your_callable)` with `sigtools.signature(your_callable)` to retrieve the signature that `sigtools` has established for the function.
Carefully review the `sigtools` documentation, particularly sections on `sigtools.wrappers` and 'Picking the appropriate arguments for forwards'. Use `sigtools.signature` frequently during development to verify the resulting signature of combined or modified callables.
pip install sigtools
import sigtools.wraps
@sigtools.wraps.wraps
def my_decorator(func):
# ...
passimport sigtools.spec
def my_function(a, b):
pass
sig = sigtools.spec.signature(my_function)import sigtools
def func1(a):
pass
def func2(b):
pass
combined_func = sigtools.combine(func1, func2)No dependency data recorded yet.