Nick Coghlan <[email protected]> added the comment:
In reviewing Meador's patch (which otherwise looks pretty good), I had a
thought about the functionality and signature of getclosurevars().
Currently, it equates "closure" to "nonlocal scope", which isn't really true -
the function's closure is really the current binding of *all* of its free
variables, and that includes globals and builtins in addition to the lexically
scoped variables from outer scopes.
So what do people think about this signature:
ClosureVars = namedtuple("ClosureVars", "nonlocals globals builtins unbound")
def getclosurevars(func):
"""Returns a named tuple of dictionaries of the current nonlocal, global
and builtin references as seen by the body of the function. A final set of
unbound names is also provided."""
# figure out nonlocal_vars (current impl)
# figure out global_vars (try looking up names in f_globals)
# figure out builtin_vars (try looking up names in builtins)
# any leftover names go in unbound_vars
return ClosureVars(nonlocal_vars, global_vars, builtin_vars, unbound_vars)
Also, something that just occurred to me is that getclosurevars() should work
for already instantiated generator iterators as well as generator functions, so
the current typecheck may need to be made a bit more flexible.
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue13062>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com