decorators - would be nice if...
Jack Diederich
jackdied at gmail.com
Tue Jul 14 19:23:31 EDT 2009
On Tue, Jul 14, 2009 at 5:44 PM, Ken Seehart<ken at seehart.com> wrote:
> Almost every time I use decorators, I find myself wishing I had access
> to the local namespace of the context from which the decorator is
> executed. In practice, decorator is being applied to a method, so the
> namespace in question would be the dictionary of the class being created.
As other mentioned, an example would make it clearer what you are trying to do.
> Similarly, before decorators were around, I often found myself lamenting
> the fact that a class is not created until after it's scope is
> completed, since this makes certain kinds of metaprogramming more
> difficult. But after digging deeper, I realized why it is the way it
> is, so I don't complain about that.
Py3k to the rescue! Because the metaclass is defined outside of the
class body it is possible to pass in a metaclass that uses a custom
dictionary. This was added to make some common cases easier (like
knowing in which order members were defined). This is not
backportable to 2.6 because the __metaclass__ is defined inside the
class body and possibly anywhere in the class body.
-Jack
More information about the Python-list
mailing list