[Python-ideas] abc.optionalabstractmethod

Steven D'Aprano steve at pearwood.info
Tue Aug 7 02:35:16 CEST 2012

On 07/08/12 08:55, Jim Jewett wrote:
> On 8/3/12, Nick Coghlan<ncoghlan at gmail.com>  wrote:
>> Really, the phrase "optional abstract method" is a bit of an oxymoron.
> Only if you place too much faith in the details on the current implementation.

I don't see that this has anything to do with implementation.

> One major use of an abstract class is to document an interface.  The
> abstract class can only define (or even document, really, if you value
> docstrings) methods that it defines.

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.

But even putting that aside, the interface that it (implicitly?) documents is 
surely *required* interface. If you can neglect to override an abstract method 
with impunity, then it shouldn't have been an abstract method in the first place.

As I see it, "optional abstract method" means "You *must* implement this 
method, but if you don't, that's okay too".


More information about the Python-ideas mailing list