There isn't any trivial way to check that the method signatures match.
However, assuming:
- Your subclass only the derives from the concerned abstract class or the abstract class is the first in its mro
- And that the implementation of the abstract class is empty, to eliminate any possibility of unwanted results such as binding new attributes to the subclass,
You could make a super
call to the abstract method passing the paramters from the subclass method. The call only serves to enforce a signature match.
class F(object):
__metaclass__ = abc.ABCMeta
@abc.abstractmethod
def f(self, a, b): pass
class FF(F):
def f(self, *args, **kwargs):
super(FF, self).f(*args, **kwargs)
...
f = FF()
f.f()
Traceback (most recent call last):
File "python", line 17, in <module>
File "python", line 12, in f
TypeError: f() takes exactly 3 arguments (1 given)
Python abstract methods (unlike others) can have implementations and can be called via super
; so maybe this is one use case after all.