On this page
inspect.Parameter
Prev: inspect.getouterframes | Up: inspect | Next: inspect.Signature
Rel: inspect.ArgInfo, inspect.Arguments, inspect.Attribute, inspect.BlockFinder
Ref: docs.python.org — inspect.Parameter
Tags: #public #python3 #stdlib #inspect
Import
import inspect
from inspect import Parameter
Signature & Overview
inspect.Parameter(name, kind, *, default, annotation)
Represents a parameter in a function signature.
Methods & Attributes
Parameter.annotation(...)—Parameter.annotationmethod/property.Parameter.default(...)—Parameter.defaultmethod/property.Parameter.empty()— Marker object for Signature.empty and Parameter.empty.Parameter.kind(...)—Parameter.kindmethod/property.Parameter.name(...)—Parameter.namemethod/property.Parameter.replace(self, *, name=<class 'inspect._void'>, kind=<class 'inspect._void'>, annotation=<class 'inspect._void'>, default=<class 'inspect._void'>)— Creates a customized copy of the Parameter.
Usage
import inspect
def fn(a, /, b=1, *, c=2): pass
params = inspect.signature(fn).parameters
assert params["a"].kind is inspect.Parameter.POSITIONAL_ONLY
assert params["c"].kind is inspect.Parameter.KEYWORD_ONLY
assert params["a"].default is inspect.Parameter.empty
Gotchas
- Check
param.default is inspect.Parameter.empty, NOTNone:Noneis a valid default value;Parameter.emptyis the sentinel for "no default".
REPL Inspect
from inspect import Parameter
help(Parameter)
Linked from
Related notes
- tuts/python3/stdlib_module/inspect/getouterframes Linked here; links to this page; shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/Signature Linked here; links to this page; shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/inspect/ArgInfo Linked here; shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/Arguments Linked here; shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/Attribute Linked here; shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/BlockFinder Linked here; shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/BoundArguments shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/BufferFlags shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/ClassFoundException shared tags: #inspect, #stdlib