how about a builtin "abstractmethod"?
Josiah Carlson
jcarlson at uci.edu
Fri Oct 22 15:00:08 EDT 2004
steve at ferg.org (Stephen Ferg) wrote:
> # 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
^^^^^
I don't believe that using a single line for such definitions are
considered Pythonic.
I prefer...
class TestClass:
def TestMethod(self):
raise NotImplementedError
Sure, you don't get the function name in your textual exception raise,
but you do get the function call in your traceback, and save yourself
having to use decorators when they are certainly not necessary, and
don't improve the readability nor understandability of the code.
- Josiah
More information about the Python-list
mailing list