我遇到了一个bug,当使用is
时,我依赖于方法相等。结果发现不是这种情况:
>>> class What:
... def meth(self):
... pass
>>> What.meth is What.meth # This is False in Python 2
True
>>> inst = What()
>>> inst.meth is inst.meth
False
为什么会这样呢?对于普通函数这是有效的:
>>> def func(): pass
>>> func is func
True
What.meth is What.meth
是成立的(返回True
),但是在Python 3.8.0中,inst = What(); inst.meth is inst.meth
返回False
。 - user3064538