Quantcast
Channel: Python: Create Abstract Static Property within Class - Stack Overflow
Browsing all 5 articles
Browse latest View live

Answer by bgfvdu3w for Python: Create Abstract Static Property within Class

This builds upon the approach of other answers that use __init_subclass__. It searches for the attribute in every base class (via its MRO) except X itself. This solves the issue of grandchildren which...

View Article



Answer by Ben Caine for Python: Create Abstract Static Property within Class

If the requirement that it be a property is flexible, you could just define a static abstract method:class X: @staticmethod @abstractmethod def var(): passclass Y(X): @staticmethod def var(): return...

View Article

Answer by Speckhouse for Python: Create Abstract Static Property within Class

Maybe a variation on your solution could work - instead of using dict simply testing whether parent's and subclass static variables are the same object.It works for grandchildren and slots, but the...

View Article

Answer by sam-6174 for Python: Create Abstract Static Property within Class

Let me know if you're aware of a more traditional way to solve this that will also work for classes that use __slots__. But for my use case, the below will work:class X: var = [1,2] def...

View Article

Python: Create Abstract Static Property within Class

What I'd really like to do is something like this:class X(metaclass=abc.ABCMeta): @abc.abstractAttribute # this doesn't exist var = [1,2]class Y(X): var = X.var + [3,4]This would force any subclasses...

View Article

Browsing all 5 articles
Browse latest View live




Latest Images