class method __instancecheck__ does not work

后端 未结 2 1527
有刺的猬
有刺的猬 2020-12-10 03:27

I am using python 2.7.3 on Windows. I tried to override the __instancecheck__ magic method as a class method. But I can not make it work.

class          


        
2条回答
  •  余生分开走
    2020-12-10 04:08

    The docs say:

    Note that these methods are looked up on the type (metaclass) of a class. They cannot be defined as class methods in the actual class. This is consistent with the lookup of special methods that are called on instances, only in this case the instance is itself a class.

    http://docs.python.org/2/reference/datamodel.html#customizing-instance-and-subclass-checks

提交回复
热议问题