Class decorators do not inherit properly

Chris Fonnesbeck listservs at
Thu Jul 12 20:49:11 CEST 2007

I have a class that does MCMC sampling (Python 2.5) that uses decorators 
-- one in particular called _add_to_post that appends the output of the 
decorated method to a class attribute. However, when I 
subclass this base class, the decorator no longer works:

Traceback (most recent call last):
  File "/Users/chris/Projects/CMR/", line 132, in <module>
    class M0(MetropolisHastings):
  File "/Users/chris/Projects/CMR/", line 173, in M0
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:

In [5]: dir(M0)

I dont see what the problem is here -- perhaps someone could shed 
some light. I thought it might be the underscore preceding the name, 
but I tried getting rid of it and that did not help.


More information about the Python-list mailing list