[Python-Dev] more timely detection of unbound locals

Nick Coghlan ncoghlan at gmail.com
Mon May 9 17:22:36 CEST 2011

On Tue, May 10, 2011 at 1:06 AM, Eli Bendersky <eliben at gmail.com> wrote:
> It probably shows the original complaint even more strongly. As for being a
> problem with the suggested solution, I suppose you're right, although it
> doesn't make it much different. Still, before a *possible* assignment to
> 'x', it should be loaded as LOAD_NAME since it was surely not bound as
> local, yet.

Yeah, I've decided I'm happier with the closure based arguments than
the conditional statement related ones. "Assignments create local
variables" is a relatively simple rule to reason about, and is equally
valid for the current scope and for any nested scopes. The symtable
analysis for nested scopes is ordering independent (and can't be
changed for backwards compatibility reasons if nothing else), and
UnboundLocalError is a natural outgrowth of applying those semantics
to the current scope as well.


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-Dev mailing list