[Python-Dev] Re: closure semantics

Zack Weinberg zack at codesourcery.com
Thu Oct 23 18:27:01 EDT 2003


Guido van Rossum <guido at python.org> writes:

>> However, as long as we're talking about this stuff, I wish I could
>> write "global foo" at module scope and have that mean "this variable
>> is to be treated as global in all functions in this module".
>
> This is similar to Greg Ewing's proposable to have 'rebindable x' at
> an outer function scope.  My problem with it remains:
>
> It gives outer scopes (some) control over inner scopes.  One of the
> guidelines is that a name defined in an inner scope should always
> shadow the same name in an outer scope, to allow evolution of the
> outer scope without affecting local details of inner scope.  (IOW if
> an inner function defines a local variable 'x', the outer scope
> shouldn't be able to change that.)

Frankly, I wish Python required one to write explicit declarations for
all variables in the program:

var x, y, z # module scope

class bar:
   classvar I, J, K # class variables
   var i, j, k      # instance variables

def foo(...):
   var a, b, c  # function scope
   ...

It's extra bondage and discipline, yeah, but it's that much more help
comprehending the program six months later, and it also gets rid of
the "how was this variable name supposed to be spelled again?"
question.

zw



More information about the Python-Dev mailing list