inspect2
raw JSON → 0.1.2 verified Fri May 01 auth: no python maintenance
Backport of Python 3.6's inspect module to Python 2.7–3.5. Provides the signature() function and other inspection features missing in older Python versions. Current version 0.1.2, low activity.
pip install inspect2 Common errors
error ImportError: cannot import name 'signature' from 'inspect' ↓
cause Python <3.4 has no inspect.signature, or Python 2.7's inspect does not have signature.
fix
Install inspect2 and use 'from inspect2 import signature'.
error TypeError: signature() got an unexpected keyword argument 'follow_wrapped' ↓
cause inspect2 version 0.1.2 does not support follow_wrapped parameter (Python 3.5+).
fix
Omit follow_wrapped or upgrade to Python 3.6+ to use inspect.signature.
Warnings
deprecated inspect2 is only needed for Python 2.7–3.5. Python 3.6+ natively includes inspect.signature; using inspect2 on Python 3.6+ may cause import conflicts. ↓
fix Use standard library 'inspect' on Python 3.6+.
gotcha inspect2 does not override the built-in inspect module. You must explicitly import from inspect2. ↓
fix Use 'from inspect2 import ...' instead of relying on inspect being patched.
Imports
- signature wrong
from inspect import signaturecorrectfrom inspect2 import signature
Quickstart
from inspect2 import signature
def foo(a, b=1):
return a + b
sig = signature(foo)
print(sig.parameters['a'].default is None)
print(sig.parameters['b'].default)