I was reading official python documentation.
In the mentioned link, the second line states that:
Using this decorator requires that the class’s metaclass is ABCMeta or is derived from it.
But, I was successfully able to define the below given class.
from abc import abstractmethod
class A(object):
def __init__(self):
self.a = 5
@abstractmethod
def f(self):
return self.a
a = A()
a.f()
So, the code above worked fine. And also, I was able to create a subclass
class B(A):
def __init__(self):
super(B, self).__init__()
b = B()
b.f()
Without overriding the abstract method defined above.
So, basically does this mean that if my base class's metaclass
is not ABCMeta
(or derived from it), the class does not behave like an abstract class even though I have an abstract method in it?
That means, the documentation needs more clarity?
Or, is this behaviour useful somehow and I'm missing the point.
Using this decorator requires that the class’s metaclass is ABCMeta or is derived from it.
to be enforced? – Hilaryhilbert