samedi 5 avril 2014

classe - méthodes abstraites avec des arguments précis en Python - Stack Overflow


I implement abstract class with abc package. The program below shows no problems.


Is there any way to make it fail because abstract MyMethod did have an argument a but the implementation of 'MyMethod' in class Derivative didn't? So I would like specify not only methods in the interface class Base but also arguments of these methods.


import abc

#Abstract class
class Base(object):
__metaclass__ = abc.ABCMeta

@abc.abstractmethod
def MyMethod(self, a):
'MyMethod prints a'


class Derivative(Base)

def MyMethod(self):
print 'MyMethod'


I implement abstract class with abc package. The program below shows no problems.


Is there any way to make it fail because abstract MyMethod did have an argument a but the implementation of 'MyMethod' in class Derivative didn't? So I would like specify not only methods in the interface class Base but also arguments of these methods.


import abc

#Abstract class
class Base(object):
__metaclass__ = abc.ABCMeta

@abc.abstractmethod
def MyMethod(self, a):
'MyMethod prints a'


class Derivative(Base)

def MyMethod(self):
print 'MyMethod'

0 commentaires:

Enregistrer un commentaire