how about a builtin "abstractmethod"?

Stephen Ferg steve at ferg.org
Fri Oct 22 09:38:50 EDT 2004


Python has a builtin class for staticmethod.  Seems to me that Python
should also have a builtin class for abstractmethod.  Something like
this...

#######################################

# simulated implementation of a new builtin class: abstractmethod
def abstractmethod(f):
    methodName = f.__name__
    def temp(self, *args, **kwargs):
        raise NotImplementedError(
            "Attempt to invoke unimplemented abstract method %s"
            % methodName)
    return temp

# example of using proposed builtin class: abstractmethod
class TestClass:
    @abstractmethod
    def TestMethod(self): pass


t = TestClass()
t.TestMethod()  # call to abstract method raises exception



More information about the Python-list mailing list