On this page
inspect.BoundArguments
Prev: inspect.BlockFinder | Up: inspect | Next: inspect.BufferFlags
Rel: inspect.ArgInfo, inspect.Arguments, inspect.Attribute, inspect.BlockFinder
Ref: docs.python.org — inspect.BoundArguments
Tags: #public #python3 #stdlib #inspect
Import
import inspect
from inspect import BoundArguments
Signature & Overview
inspect.BoundArguments(signature, arguments)
Result of Signature.bind call. Holds the mapping of arguments to the function's parameters.
Methods & Attributes
BoundArguments.apply_defaults(self)— Set default values for missing arguments.BoundArguments.args(...)—BoundArguments.argsmethod/property.BoundArguments.kwargs(...)—BoundArguments.kwargsmethod/property.BoundArguments.signature(...)—BoundArguments.signaturemethod/property.
Usage
import inspect
def greet(name: str, excited: bool = False) -> str:
return f"hi {name}"
sig = inspect.signature(greet)
bound = sig.bind("Ada")
bound.apply_defaults()
assert isinstance(bound, inspect.BoundArguments)
assert bound.arguments == {"name": "Ada", "excited": False}
Gotchas
- Call
bound.apply_defaults(): Without it, defaulted parameters omitted by the caller won't appear inbound.arguments.
REPL Inspect
from inspect import BoundArguments
help(BoundArguments)
Linked from
Related notes
- tuts/python3/stdlib_module/inspect/ArgInfo Linked here; links to this page; shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/Arguments Linked here; links to this page; shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/Attribute Linked here; links to this page; shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/BlockFinder Linked here; links to this page; shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/BufferFlags 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/ClassFoundException shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/classify_class_attrs shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/cleandoc shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/ClosureVars shared tags: #inspect, #stdlib