[Python-Dev] terminology for "free variables" in Python
Eli Bendersky
eliben at gmail.com
Thu Sep 9 18:43:54 CEST 2010
The execution model section of the Python reference manual defines free
variables as follows:
"If a variable is used in a code block but not defined there, it is
a free variable"
This makes sense and fits the academic definition. The documentation of the
symtable module supports this definition - it says about is_free(): "return
True if the symbol is referenced in its block but not assigned to".
However, it appears that in the CPython front-end source code (in particular
the parts dealing with the symbol table), a free variables has a somewhat
stricter meaning. For example, in this chunk of code:
def some_func(myparam):
def internalfunc():
return cc * myparam
CPython infers that in 'internalfunc', while 'myparam' is free, 'cc' is
global because 'cc' isn't bound in the enclosing scope, although according
to the definitions stated above, both should be considered free. The
bytecode generated for loading cc and myparam is different, of course.
Is there a (however slight) inconsistency of terms here, or is it my
misunderstanding?
Thanks in advance,
Eli
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20100909/e077479d/attachment.html>
More information about the Python-Dev
mailing list