On this page
inspect.ClosureVars
Prev: inspect.cleandoc | Up: inspect | Next: inspect.currentframe
Rel: inspect.ArgInfo, inspect.Arguments, inspect.Attribute, inspect.BlockFinder
Ref: docs.python.org โ inspect.ClosureVars
Tags: #public #python3 #stdlib #inspect
Import
import inspect
from inspect import ClosureVars
Signature & Overview
inspect.ClosureVars(nonlocals, globals, builtins, unbound)
ClosureVars(nonlocals, globals, builtins, unbound)
Methods & Attributes
ClosureVars.count(self, value, /)โ Return number of occurrences of value.ClosureVars.index(self, value, start=0, stop=9223372036854775807, /)โ Return first index of value.
Usage
import inspect
GLOBAL_X = 10
def make():
local_y = 5
return lambda z: GLOBAL_X + local_y + z
cv = inspect.getclosurevars(make())
assert isinstance(cv, inspect.ClosureVars) and cv.nonlocals == {"local_y": 5}
Gotchas
- Returned by
inspect.getclosurevars(func): Splits external references into.nonlocals,.globals,.builtins, and.unbound.
REPL Inspect
from inspect import ClosureVars
help(ClosureVars)
Linked from
Related notes
- tuts/python3/stdlib_module/inspect/cleandoc Linked here; links to this page; shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/currentframe 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