Class decorators do not inherit properly

Lee Harr missive at frontiernet.net
Thu Jul 12 18:24:15 EDT 2007


> Traceback (most recent call last):
>   File "/Users/chris/Projects/CMR/closed.py", line 132, in <module>
>     class M0(MetropolisHastings):
>   File "/Users/chris/Projects/CMR/closed.py", line 173, in M0
>     @_add_to_post
> NameError: name '_add_to_post' is not defined
>
> yet, when I look at the dict of the subclass (here called M0), I see the 
> decorator method:
>


I think the term "class decorator" is going to eventually
mean something other than what you are doing here. I'd
avoid the term for now.


When you decorate a class method, the function you use
needs to be defined before the method definition.

Using a class method to decorate another class method is
going to be tricky. The way I usually do it is to create
a separate function outside of the class definition for
the decorator function.


You're going to have to show us the actual code you are
having trouble with, or else (probably more useful, really)
try to put together a minimal example of what you are
trying to do and show us that code.




More information about the Python-list mailing list