Is it possible to extend a class which has a decorator applied to it? For example:
@someDecorator
Class foo(object):
...
...
Class bar(foo):
...
...
Ideally bar would not be affected by the decorator, but first I want to find out if this is even possible. Currently I am getting a non-runtime error:
“TypeError: Error when calling the metaclass bases
function() argument 1 must be code, not str
“
Any suggestions?
As Matt put it, your decorator is not working. Whenever you get your decorator to work properly (make some tests, even imediate tests by copying and paste to a console):
What the (valid) decorator returns is your class “foo” – you can’t access what it was before the decorator being applied if you use the decorator syntax.
However, decorators in Python are a syntatic sugar to replace the following declared function or class with what is returned by processing that function or class with the decorator. Thus, these are equivalent:
and
Therefore, you can achieve the effect of extending a class before applying the decorator simply by doing: