python - How to use the __subclasscheck__ magic method? -


how can make class lies has subclassed?

after reading doc i've attempted this:

>>> class allyourbase(type): ...     @classmethod ...     def __subclasscheck__(cls, other): ...         return true ...      >>> class allyour(object): ...     __metaclass__ = allyourbase 

now, class should report base belong him.

but didn't work:

>>> issubclass(allyour, int) false 

why not?

if want allyour claim subclass of every class, isn't possible. __subclasscheck__ works in other direction.

if want allyour claim every class subclasses it, remove @classmethod decorator, , switch arguments in issubclass call. special methods define on metaclass don't need special decoration.


Comments

Popular posts from this blog

multithreading - Exception in Application constructor -

React Native allow user to reorder elements in a scrollview list -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -