I have read python docs about abstract base classes:
From here:
abc.abstractmethod(function)
A decorator indicating abstract methods.Using this decorator requires that the class’s metaclass is
ABCMeta
or is derived from it. A class that has a metaclass derived fromABCMeta
cannot be instantiated unless all of its abstract methods and properties are overridden.
And here
You can apply the
@abstractmethod
decorator to methods such as draw() that must be implemented; Python will then raise an exception for classes that don’t define the method. Note that the exception is only raised when you actually try to create an instance of a subclass lacking the method.
I've used this code to test that out:
import abc
class AbstractClass(object):
__metaclass__ = abc.ABCMeta
@abc.abstractmethod
def abstractMethod(self):
return
class ConcreteClass(AbstractClass):
def __init__(self):
self.me = "me"
c = ConcreteClass()
c.abstractMethod()
The code goes fine, so I don't get it. If I type c.abstractMethod
I get:
<bound method ConcreteClass.abstractMethod of <__main__.ConcreteClass object at 0x7f694da1c3d0>>
What I'm missing here? ConcreteClass
must implement the abstract methods, but I get no exception.
abc
. – Hoskinsonpython
was set as default topython3
. I'll keep in mind raising the exception, as writting portable code with that changes on python seems far away from my python knowledge. – Anaplasty