This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ncoghlan
Recipients Yury.Selivanov, daniel.urban, eric.snow, meador.inge, ncoghlan
Date 2011-10-10.16:00:18
SpamBayes Score 1.6452593e-06
Marked as misclassified No
Message-id <1318262419.42.0.246264413161.issue13062@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2011-10-10 16:00:19ncoghlansetrecipients: + ncoghlan, meador.inge, daniel.urban, Yury.Selivanov, eric.snow
2011-10-10 16:00:19ncoghlansetmessageid: <1318262419.42.0.246264413161.issue13062@psf.upfronthosting.co.za>
2011-10-10 16:00:18ncoghlanlinkissue13062 messages
2011-10-10 16:00:18ncoghlancreate