Search code examples
pythonabstract-class

Abstract class without any inheritance


Basically, I know that abstract base classes are used as skeleton classes just like regular classes, and there main advantage would be to enforce their implementation on the child classes.

But I was wondering if I have the next case:

I have a class which is having only static methods / no init -> it would make sense to make it abstract? It would be pythonic?

I was thinking the advantage would be that some one reading the code would know that that class should not be instantiated...


Solution

  • It seems that you're trying to emulate namespaces. It's better to use modules. The mechanism is built into Python, and functions as a namespace:

    https://docs.python.org/3/tutorial/modules.html

    An abstract class with only static-methods can work as a namespace, but it's confusing to people reading the source code