This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients bup, rhettinger, serhiy.storchaka
Date 2018-08-02.03:37:07
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1533181027.61.0.56676864532.issue34314@psf.upfronthosting.co.za>
In-reply-to
Content
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
History
Date User Action Args
2018-08-02 03:37:07serhiy.storchakasetrecipients: + serhiy.storchaka, rhettinger, bup
2018-08-02 03:37:07serhiy.storchakasetmessageid: <1533181027.61.0.56676864532.issue34314@psf.upfronthosting.co.za>
2018-08-02 03:37:07serhiy.storchakalinkissue34314 messages
2018-08-02 03:37:07serhiy.storchakacreate