Special Method Protocols
__subclasscheck__() — class creation protocol
Metaclass hook controlling issubclass(subclass, cls). Supports virtual subclass policies; ordinary inheritance need not be changed. Avoid recursive checks on the same target.
Formal Syntax & Structure
python syntaxpython
def __subclasscheck__(cls, subclass):Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| subclass | type | Class being tested. |
Return Value
bool
Whether subclass qualifies.
Working Example
Example Snippetpython
class Meta(type): def __subclasscheck__(cls, subclass): return getattr(subclass,"ready",False) is Trueclass Ready(metaclass=Meta): passclass Job: ready=Trueprint(issubclass(Job, Ready))