[Python-Dev] One-line abstractmethod function?
Alexander Belopolsky
alexander.belopolsky at gmail.com
Thu Dec 5 19:56:25 CET 2013
On Thu, Dec 5, 2013 at 1:24 PM, Guido van Rossum <guido at python.org> wrote:
> How would you get the docstrings in? It seems cramming that much on a
> single line doesn't help readability (even though I agree there is a
> fair amount of boilerplace).
>
One way to reduce the amount of boilerplate code is to make abstractmethod
to supply raise NotImplementedError body when none is given. Then you can
write
class Foo:
@abc.abstractmethod
def do_bar(self):
"""perform bar"""
instead of
class Foo:
@abc.abstractmethod
def do_bar(self):
"""perform bar"""
raise NotImplementedError
The docstring will be required when skipping the body which is probably a
good thing.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20131205/eee07a55/attachment.html>
More information about the Python-Dev
mailing list