On this page
  1. inspect.ClosureVars
  2. Import
  3. Signature & Overview
  4. Methods & Attributes
  5. Usage
  6. Gotchas
  7. REPL Inspect

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

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

REPL Inspect

from inspect import ClosureVars
help(ClosureVars)

Linked from

Related notes