Are decorators really that different from metaclasses...

Anthony Baxter anthonybaxter at gmail.com
Thu Aug 26 03:31:16 EDT 2004


On Wed, 25 Aug 2004 19:47:35 -0400, Paul Morrow <pm_mon at yahoo.com> wrote:
> What you're trying to illustrate (I believe) is a superclass doing
> something based on the docstring of a subclass.  Yes this certainly does
> happen.  But the superclass and subclass are separate objects.  I was
> talking about the situation where a function does something based on
> /its own/ metadata.  That is what I'm saying virtually never happens,
> and therefore it's ok to make all assignments to __xxx__ attributes
> inside of a function def create /function attributes/ rather than /local
> variables/.

This is an extraordinarily complex idea - you're proposing that inside
a function there is now access to a brand new namespace, that of the
function object itself. I don't think you appreciate just _how_ much
work this would requre, nor the complexity of trying to explain this
to users. Remember, at the moment, you can't even get access to the
function object itself from inside the function, without using a hack
like sys._getframe() or raising an exception.

Putting aside nested scopes for the moment, there are three namespaces
that are used in Python - local, module level global, and builtins.
You're proposing that there is a new namespace, that of the function
object, and that it only be used by accessing any local variable that
starts or ends with two underscores. At the moment, the scoping rules
for Python are _extremely_ simple. Do you really want to add something
like this, that looks like a hack, smells like a hack, and who's
implementation would be a hack? I know I don't want to see something
like this.



More information about the Python-list mailing list