Python inspection tool!
Created: 2025-10-12 17:38:07 | Last updated: 2025-10-12 17:38:07 | Status: Public
Key Introspection Tools
import inspect
# See function/method signatures (parameters, types, defaults)
inspect.signature(SomeClass.__init__)
inspect.signature(some_function)
# Get the source code of a function/class
print(inspect.getsource(some_function))
# List all methods/attributes of an object
dir(some_object)
# Get detailed info about any object
help(SomeClass)
# Check if something is callable, a class, a function, etc.
inspect.isfunction(x)
inspect.isclass(x)
inspect.ismethod(x)
Real-World Usage
When you’re working with unfamiliar libraries (especially poorly documented ones), this is gold:
# Quick signature check
python3 -c "from library import Class; import inspect; print(inspect.signature(Class.method))"
# See what's available in a module
python3 -c "import library; print([x for x in dir(library) if not x.startswith('_')])"
# Get full source of a troublesome function
python3 -c "import inspect; from library import func; print(inspect.getsource(func))"
This is especially useful when:
- Documentation is outdated/wrong (like we just saw with OpenWakeWord)
- You’re debugging third-party code
- APIs changed between versions
- You need to understand parameter types/defaults
Way better than digging through GitHub or hoping the docs are current. You’re reading the actual running code.