[Python-ideas] nonlocal functions

Masklinn masklinn at masklinn.net
Wed Oct 21 14:43:07 CEST 2009

On 21 Oct 2009, at 13:50 , Nick Coghlan wrote:
> You're also omitting consideration of the ways *other* than assignment
> to bind a name in Python (i.e. def, with, except, for). Would those
> require an explicit let as well?

> If not, why single out assignment as a
> special case that requires an explicit declaration of "Yes, I really  
> do
> want to create a new local here"?
Because in all those other cases, the fact that you "really do want to  
create a new local here" is part of the statement's semantics. Why  
repeat it?

> giving up one of the major benefits of dynamic typing (i.e.
> no need for variable declarations).
I don't see that as a benefit of dynamic typing (in fact I don't even  
see that as relevant to dynamic typing, some dynamically typed  
languages have implicit locals declaration, others have explicit  
locals — and scope — declaration). And even if it were a benefit of  
dynamic typing, it's hardly a major one, and it's one with a bunch of  
drawbacks as scope inference tends to be unreliable and messy (leading  
to the need for `global` and `nonlocal` in Python).

More information about the Python-ideas mailing list