Message322909
Setting __hash__ to None doesn't do what you think. It doesn't prevent __hash__ from being called by hash(), instead it produces a TypeError.
>>> class A: __hash__ = None
...
>>> hash(A())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'A'
Actually the effect of special casing __hash__ is not raising a TypeError, but raising a TypeError with better error message. A TypeError was already raised before if set __hash__ to a non-callable. In 2.7:
>>> class A: __hash__ = None
...
>>> hash(A())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not callable
If you want to prevent an inherited __init__ from being called by types's __call__, you can define an __init__ with an empty body.
def __init__(self, *args, **kwargs):
pass |
|
Date |
User |
Action |
Args |
2018-08-02 03:37:07 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka, rhettinger, bup |
2018-08-02 03:37:07 | serhiy.storchaka | set | messageid: <1533181027.61.0.56676864532.issue34314@psf.upfronthosting.co.za> |
2018-08-02 03:37:07 | serhiy.storchaka | link | issue34314 messages |
2018-08-02 03:37:07 | serhiy.storchaka | create | |
|