ABCMeta change isinstancecheck of additional parent class?

Hey all. I lecture by advanced python and after lesson which is devoted by metaclasses, my student found several interest examples.

This code:

from abc import ABC, ABCMeta

class A(ABC): # ABC is need for this example
    pass

class MyABCMeta(ABCMeta, A): # Yes, not metaclass=ABCMeta
    pass

isinstance(1, A)

raised next exception: TypeError: unbound method type.__subclasses__() needs an argument

This example can be modificated:

from abc import ABC, ABCMeta
class A(ABC):
    pass

isinstance(1, A) # work correct

class MyABCMeta(ABCMeta, A):
    pass

isinstance(1, A) # Also work correct, cached for int type
isinstance("a", A) # Another type raise exception

Do I understand correctly what ABCMeta in MyABCMeta change class A, which hasn’t direct relations with MyABCMeta (A metaclassing by ABCMeta, but don’t inheritance its).
This is bug or features???

2 Likes