Python decorator to add class-level variables

Viewed 1809

I have 2 classes A and B:

class A(object):
    x = 0

class B(object):
    y = 0

How can I make it so B "inherits" A's class-level variables (x in this case) by using decorators? Is it at all possible? The desired behavior (if possible), after decorated, B would look like this:

class B(object):
    x = 0
    y = 0

Note: If anyone wants/needs to know why I'm asking this, it's simply to make SQLAlchemy's Concrete Table Inheritance look nicer in code, although I can see many use cases for such behavior.

1 Answers
Related