How can I make a class or method abstract in Python?
I tried redefining __new__()
like so:
class F:
def __new__(cls):
raise Exception("Unable to create an instance of abstract class %s" %cls)
But now, if I create a class G
that inherits from F
like so:
class G(F):
pass
Then, I can't instantiate G
either, since it calls its super class's __new__
method.
Is there a better way to define an abstract class?