[Python-ideas] Consider allowing the use of abstractmethod without metaclasses

Neil Girdhar mistersheik at gmail.com
Fri Jul 7 21:25:38 EDT 2017

I want to use abstractmethod, but I have my own metaclasses and I don't 
want to build composite metaclasses using abc.ABCMeta.

Thanks to PEP 487, one approach is to facator out the abstractmethod checks 
from ABCMeta into a regular (non-meta) class.  So, my first suggestion is 
to split abc.ABC into two pieces, a parent regular class with metaclass 

class AbstractBaseClass:

    def __init_subclass__(cls):
        # Compute set of abstract method names
        abstracts = {name
                     for name, value in vars(cls).items()
                     if getattr(value, "__isabstractmethod__", False)}
        for base in cls.__bases__:
            for name in getattr(base, "__abstractmethods__", set()):
                value = getattr(cls, name, None)
                if getattr(value, "__isabstractmethod__", False):
        cls.__abstractmethods__ = frozenset(abstracts)

My alternative suggestion is to move this logic directly into "type" so 
that all classes have this logic, and then move abstractmethod into 

Of course, this isn't pressing since I can do this in my own code, it's 
just a suggestion from a neatness standpoint.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170707/7cfae08f/attachment.html>

More information about the Python-ideas mailing list