19.7 inspect.signature() and Introspecting Callables
The inspect.signature() function is the cornerstone of runtime callable introspection in Python, providing a powerful, standardized way to examine the parameters a function or method expects. It returns a Signature object, which is a rich, structured representation of the callable’s signature, far surpassing the basic information provided by older methods like inspect.getargspec() (now deprecated). This object allows you to programmatically understand not just the names of parameters, but also their kinds (positional, keyword, etc.), default values, and annotations, making it indispensable for building frameworks, decorators, validation libraries, and interactive tools.