This isn't possible because of the way Python handles duck typing in abstract base classes. Using
__subclasshook__ an abc can specify any arbitrary logic to determine if a given class is a subclass of it. For example, from the
class MyIterable(ABC): # <snipped> @classmethod def __subclasshook__(cls, C): if cls is MyIterable: if any("__iter__" in B.__dict__ for B in C.__mro__): return True return NotImplemented
This code says that the class
C is a subclass of
MyIterable if it contains the method
__iter__. If you have an arbitrary class
X that contains
__iter__ it is a subclass of
MyIterable even though
X never expressly extends or is even aware of the existence of
MyIterable. Therefore, the only way to discover if a given class is a subclass of a set of abstract classes is to check each of them using
Given that the "subset of abstract bases classes" that you want to check is the set of all abstract base classes, and since there can be an infinite number of arbitrary abstract base classes in the world, it is not possible to test them all.
Of course, this is Python where nothing is truly private. It is technically possible to see all of the classes that are currently imported into your code by recursively scanning
sys.modules, and testing against all of them using
issubclass, but I can't imagine this being feasible in any real-world program.