{"id":2285,"library":"sigtools","title":"Utilities for working with inspect.Signature objects","description":"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.","status":"active","version":"4.0.1","language":"en","source_language":"en","source_url":"https://github.com/epsy/sigtools","tags":["signature","introspection","decorators","inspect","callable","metaprogramming"],"install":[{"cmd":"pip install sigtools","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"note":"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`.","wrong":"import inspect; inspect.signature(func)","symbol":"signature","correct":"from sigtools import signature"},{"symbol":"specifiers","correct":"from sigtools import specifiers"},{"symbol":"wrappers","correct":"from sigtools import wrappers"},{"symbol":"modifiers","correct":"from sigtools import modifiers"}],"quickstart":{"code":"from sigtools import signature\n\ndef original_func(a, b):\n    pass\n\n@signature(original_func)\ndef wrapped_func(c, d):\n    # This function's signature is now effectively (a, b) due to @signature(original_func)\n    pass\n\nprint(f\"Original signature: {signature(original_func)}\")\nprint(f\"Wrapped signature: {signature(wrapped_func)}\")\n","lang":"python","description":"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`."},"warnings":[{"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.","message":"Sigtools 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.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Replace `inspect.signature(your_callable)` with `sigtools.signature(your_callable)` to retrieve the signature that `sigtools` has established for the function.","message":"When `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`.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"Combining 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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}