[Python-Dev] One-line abstractmethod function?
Ethan Furman
ethan at stoneleaf.us
Thu Dec 5 22:28:03 CET 2013
On 12/05/2013 10:20 AM, Allen Li wrote:
>
> 90% of the time, it ends up looking something like this:
>
> class Foo(metaclass=abc.ABCMeta):
>
> @abc.abstractmethod
> def f1(self):
> raise NotImplementedError
>
> @staticmethod
> @abc.abstractmethod
> def f2(arg1):
> raise NotImplementedError
I think we're getting sidetracked by the `raise NotImplementedError` -- why do you have that line in there? If I
understand the ABCs correctly a class that does *not* have concrete methods to replace the abstract methods will raise
an exception at class creation time, so why do you need the `raise NotImplementedError`? It would only ever happen on a
super() type of call.
Having said all that, I would hope that any abstract class I had to implement would have good doc strings, and the
multi-line format is much easier to read.
-1 on the one-liner.
--
~Ethan~
More information about the Python-Dev
mailing list