Eri*_*ric 5 python hash inheritance python-2.x python-3.x
以下代码在 python 2.7 中有效,但在 python 3.5 中失败:
class Base(object):
def __hash__(self):
return 4
class Derived(Base): pass
class DerivedEquatable(Base):
def __eq__(self, other):
return False
assert Base.__hash__ is not None
assert Derived.__hash__ is not None
assert DerivedEquatable.__hash__ is not None # AssertionError in python 3
Run Code Online (Sandbox Code Playgroud)
这种行为改变记录在哪里?
| 归档时间: |
|
| 查看次数: |
661 次 |
| 最近记录: |