[Python-Dev] terminology for "free variables" in Python

Eli Bendersky eliben at gmail.com
Fri Sep 10 09:00:03 CEST 2010


>> def some_func(myparam):

> >     def internalfunc():
> >         return cc * myparam
> >
> > CPython infers that in 'internalfunc', while 'myparam' is free, 'cc' is
>
> What exactly do you mean by "infers" ? How do you know that it infers
> that? How does it matter for your understanding of the code?
>

The easiest way I found to see what CPython thinks is use the 'symtable'
module. With its help, it's clear that in the function above, myparam is
considered free while cc is considered global. When querying symtable about
the symbol myparam, the is_free method returns True while the is_global
method returns False, and vice versa for cc.

Of course it can also be seen in the code of symtable.c in function
analyze_name, and as Nick showed in his message it also affects the way
bytecode is generated for the two symbols.

My intention in this post was to clarify whether I'm misunderstanding
something or the term 'free' is indeed used for different things in
different places. If this is the latter, IMHO it's an inconsistency, even if
a small one. When I read the code I saw  'free' I went to the docs only to
read that 'free' is something else. This was somewhat confusing.

Eli
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20100910/05b6b373/attachment.html>


More information about the Python-Dev mailing list