On Fri, Sep 10, 2010 at 12:00 AM, Eli Bendersky <eli...@gmail.com> wrote: >>> 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.
I'm still not clear if my explanation that globals are a subset of free variables got rid of the confusion. The full name for what CPython marks as "free" would be "free but not global" but that's too much of a mouthful. Also you're digging awfully deep into the implementation here -- AFAIC CPython could have called them "type A" and "type B" and there would not have been any problem for compliance with the langage reference. -- --Guido van Rossum (python.org/~guido) _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com