Registry / serialization / sigtools

sigtools

JSON →
library4.0.1pypypi✓ verified 24d ago

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 sigtools
INSTALL
IMPORT
SIG · SIGTOOLS
S
sigtools
serializationpythonv4.0.1
Install
1.6s avg
Import
93ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v4.0.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.098s · 18.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.088s · 19MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

signature
from sigtools import signature
import inspect; inspect.signature(func)
When using `sigtools` decorators or features, `inspect.signature` may not reflect the *effective* signature of the callable. Always use `sigtools.signature` to get the correct signature managed by `sigtools`.
specifiers
from sigtools import specifiers
wrappers
from sigtools import wrappers
modifiers
from sigtools import modifiers

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`.

from sigtools import signature def original_func(a, b): pass @signature(original_func) def wrapped_func(c, d): # This function's signature is now effectively (a, b) due to @signature(original_func) pass print(f"Original signature: {signature(original_func)}") print(f"Wrapped signature: {signature(wrapped_func)}")
Debug
Known issues
breakingSigtools versions 4.0.0 and above officially require Python 3.6 or newer. Older versions offered Python 2 compatibility or backports, but this support has been removed.
fix
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.
affects: >=4.0.0
gotchaWhen `sigtools` decorators (like `@signature`, `@specifiers.forwards_to`, `@modifiers.kwoargs`) are applied to a callable, the standard `inspect.signature` will often *not* reflect the modified or intended effective signature. Always use `sigtools.signature` for accurate introspection of callables managed by `sigtools`.
fix
Replace `inspect.signature(your_callable)` with `sigtools.signature(your_callable)` to retrieve the signature that `sigtools` has established for the function.
affects: All versions
gotchaCombining functions with `sigtools.wrappers` or managing argument forwarding with `sigtools.specifiers` can introduce complexity in understanding how arguments are mapped or interpreted. Misunderstanding these mechanisms can lead to unexpected `TypeError` or `AttributeError` exceptions.
fix
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.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'sigtools'
The 'sigtools' package has not been installed in the current Python environment.
fix
pip install sigtools
TypeError: 'module' object is not callable
The user attempted to use `sigtools.wraps` directly as a decorator, but `sigtools.wraps` is a module, not a callable decorator itself.
fix
import sigtools.wraps

@sigtools.wraps.wraps
def my_decorator(func):
    # ...
    pass
TypeError: sigtools.spec.signature() argument must be a callable
The `sigtools.spec.signature` function was called with an argument that is not a callable object (e.g., an integer, string, or another non-function object).
fix
import sigtools.spec

def my_function(a, b):
    pass

sig = sigtools.spec.signature(my_function)
TypeError: All passed functions must be callable
One or more of the arguments provided to `sigtools.combine()` was not a callable object.
fix
import sigtools

def func1(a):
    pass
def func2(b):
    pass

combined_func = sigtools.combine(func1, func2)
Upgrade
Version history
4.0.1latest on PyPI · released Oct 13, 2022
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
6
Resources
sigtools — pip install sigtools · libregistry