[Python-ideas] abc.optionalabstractmethod

alex23 wuwei23 at gmail.com
Tue Aug 7 04:09:49 CEST 2012


On Aug 7, 10:35 am, Steven D'Aprano <st... at pearwood.info> wrote:
> I don't know that I accept that abstract classes are documentation. It seems
> to me that to be documentation, it has to be, well, documentation. Not a class
> hierarchy. The documentation might include the fact that something is an
> abstract class, but merely making something an abstract class is not in and of
> itself documentation.

Why not? What could I say here in textual documentation that isn't
made obvious by declaring the interface?

    import abc

    class XBuilder(object):
        """Interface for setting up, updating & deleting objects for
X"""

        __metaclass__ = abc.ABCMeta

        @abc.abstractmethod
        def setup(self):
            """Get the object ready for use"""

        @abc.abstractmethod
        def update(self):
            """Modify the object to reflect recent changes"""

        @abc.abstractmethod
        def delete(self):
            """Remove the object"""

Good code _is_ documentation.



More information about the Python-ideas mailing list