Metaclasses
Interfaces for the metaclass hooks behind
isinstance() and
issubclass().
These special methods are looked up on the type (i.e. the metaclass) of the operand.
| operator | operand | |
|---|---|---|
| expression | method | type |
isinstance(x, _) |
__instancecheck__ |
CanInstancecheck |
issubclass(c, _) |
__subclasscheck__ |
CanSubclasscheck |
Note
Unlike every other Can* protocol, CanSubclasscheck is not
@runtime_checkable, so it cannot be used with isinstance() or
issubclass(). Its __subclasscheck__ member shadows the method that
ABCMeta invokes internally during a runtime protocol check, which would
otherwise crash. It remains fully usable for static typing.