On Dec 31, 2019, at 09:43, Soni L. <fakedme+py@gmail.com> wrote:
I would like this code to work, but currently python ignores __subclasscheck__ in many places where it checks for subclasses:
class MM(type): def __subclasscheck__(self, subclass): return issubclass(subclass, type)
class M(type, metaclass=MM): pass
class N(type): pass
class C(metaclass=M): pass
class D(metaclass=N): pass
class E(C, D, metaclass=N): pass
Is the problem you’re trying to solve here, that you want to be able to override the metaclass conflict check in class definitions, so you can allow this? If so, I think it makes sense. N is (trivially) a subclass of the N (the metaclass of D), and you’re making it a virtual subclass (via MM) of M (the metaclass of C). So there actually is no conflict if you take virtual subclasses into account; N is unambiguously the most derived metaclass. (I suppose it would be ambiguous again if you also made M a (virtual or direct) subclass of N, but that’s probably consulting-adults territory: don’t do that, and if you do, the fact that the error message isn’t as meaningful as it could be isn’t a huge deal.) But you said “many places”. Is there a wider class of places, that includes the metaclass conflict check, where virtual subclassing is ignored but (you think) shouldn’t be?