parameters: (func)
return_statement: return ClosureVars(nonlocal_vars, global_vars,
                         builtin_vars, unbound_names)
docstring: Get the mapping of free variables to their current values.
  
      Returns a named tuple of dicts mapping the current nonlocal, global
      and builtin references as seen by the body of the function. A final
      set of unbound names that could not be resolved is also provided.
docstring_summary: Get the mapping of free variables to their current values.
docstring_tokens: Get the mapping of free variables to their current values .
function: def getclosurevars(func):
      """
      Get the mapping of free variables to their current values.
  
      Returns a named tuple of dicts mapping the current nonlocal, global
      and builtin references as seen by the body of the function. A final
      set of unbound names that could not be resolved is also provided.
      """
  
      if ismethod(func):
          func = func.__func__
  
      if not isfunction(func):
          raise TypeError("{!r} is not a Python function".format(func))
  
      code = func.__code__
      # Nonlocal references are named in co_freevars and resolved
      # by looking them up in __closure__ by positional index
      if func.__closure__ is None:
          nonlocal_vars = {}
      else:
          nonlocal_vars = {
              var : cell.cell_contents
              for var, cell in zip(code.co_freevars, func.__closure__)
         }
  
      # Global and builtin references are named in co_names and resolved
      # by looking them up in __globals__ or __builtins__
      global_ns = func.__globals__
      builtin_ns = global_ns.get("__builtins__", builtins.__dict__)
      if ismodule(builtin_ns):
          builtin_ns = builtin_ns.__dict__
      global_vars = {}
      builtin_vars = {}
      unbound_names = set()
      for name in code.co_names:
          if name in ("None", "True", "False"):
              # Because these used to be builtins instead of keywords, they
              # may still show up as name references. We ignore them.
              continue
          try:
              global_vars[name] = global_ns[name]
          except KeyError:
              try:
                  builtin_vars[name] = builtin_ns[name]
              except KeyError:
                  unbound_names.add(name)
  
      return ClosureVars(nonlocal_vars, global_vars,
                         builtin_vars, unbound_names)
function_tokens: def getclosurevars ( func ) : if ismethod ( func ) : func = func . __func__ if not isfunction ( func ) : raise TypeError ( "{!r} is not a Python function" . format ( func ) ) code = func . __code__ # Nonlocal references are named in co_freevars and resolved # by looking them up in __closure__ by positional index if func . __closure__ is None : nonlocal_vars = { } else : nonlocal_vars = { var : cell . cell_contents for var , cell in zip ( code . co_freevars , func . __closure__ ) } # Global and builtin references are named in co_names and resolved # by looking them up in __globals__ or __builtins__ global_ns = func . __globals__ builtin_ns = global_ns . get ( "__builtins__" , builtins . __dict__ ) if ismodule ( builtin_ns ) : builtin_ns = builtin_ns . __dict__ global_vars = { } builtin_vars = { } unbound_names = set ( ) for name in code . co_names : if name in ( "None" , "True" , "False" ) : # Because these used to be builtins instead of keywords, they # may still show up as name references. We ignore them. continue try : global_vars [ name ] = global_ns [ name ] except KeyError : try : builtin_vars [ name ] = builtin_ns [ name ] except KeyError : unbound_names . add ( name ) return ClosureVars ( nonlocal_vars , global_vars , builtin_vars , unbound_names )