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
"type":
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):
abstracts.add(name)
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
builtins.
Of course, this isn't pressing since I can do this in my own code, it's
just a suggestion from a neatness standpoint.
Best,
Neil
_______________________________________________
Python-ideas mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/