inspect.signature() builds a Signature whose every Parameter is constructed through the public Parameter constructor, which validates the name and kind on each call. When the parameters come from a function's own code object the names are already valid identifiers and the kinds are already the canonical constants, so that validation re-checks facts that are guaranteed to hold.
Signature introspection runs constantly in the ecosystem: web frameworks resolving view and dependency arguments, CLI libraries like click, pytest fixture wiring, and serialization and validation layers all call it per function, often at import time while wiring an application together.
Taking the signature of 400 real callables collected from popular packages (requests, click, jinja2, sqlalchemy, werkzeug, flask and others) takes 1.46 ms today and 1.16 ms when trusted-source parameters skip the redundant validation, 26% faster, with the public Parameter() constructor and its validation unchanged for every other caller.
Linked PRs
inspect.signature()builds aSignaturewhose everyParameteris constructed through the publicParameterconstructor, which validates the name and kind on each call. When the parameters come from a function's own code object the names are already valid identifiers and the kinds are already the canonical constants, so that validation re-checks facts that are guaranteed to hold.Signature introspection runs constantly in the ecosystem: web frameworks resolving view and dependency arguments, CLI libraries like
click, pytest fixture wiring, and serialization and validation layers all call it per function, often at import time while wiring an application together.Taking the signature of 400 real callables collected from popular packages (
requests,click,jinja2,sqlalchemy,werkzeug,flaskand others) takes 1.46 ms today and 1.16 ms when trusted-source parameters skip the redundant validation, 26% faster, with the publicParameter()constructor and its validation unchanged for every other caller.Linked PRs