New statement proposal for Python

Alex Martelli aleaxit at
Sun Jun 17 14:14:20 CEST 2001

"Remco Gerlich" <scarblac at> wrote in message
news:slrn9ip10q.88g.scarblac at
> Adding a way to block rebinding of a name would be a horribly inconsistent
> wart on the language.

I think this is a slight overbid.  It is perfectly possible in Python to
"block rebinding" of an object's attribute (__setattr__ easily allows
that), after all, yet the sky hasn't fallen.  One could similarly allow
blocking the rebinding of a container's item (you can do that for a
user-defined container, with __setitem__, though not on dictionaries
or lists -- tuples do "block the rebindinding" of their items).  Such
'blocking' is occasionally useful to help avoid accidental rebinding
of things that are not meant to be rebound.

Thus, I do not believe it would at all be "a wart of the language" if
Python was very slightly extended to either allow a user-defined
mapping object to be set as the __dict__ attribute of a module
(where now a bona fide dictionary must be used instead), or to
make builtin dictionaries slightly more powerful (adding a method
that let them block rebinding of some of their items).

With either of these slight extensions, there WOULD then most
naturally emerge "a way to block rebinding of a name" in every
case in which the namespace is a dictionary (not necessarily for
local variables of a function -- the local-namespace optimization
impedes many generalizations of this kind, of course, although
it's apparently indispensable for performance reasons).

And what would be wart-y about it *at all*?  Isn't it rather a
small wart that a user-defined mapping CANNOT be used for
any role for which a real-dictionary can...?


More information about the Python-list mailing list