From 37c6555b4419eb6027a345ee0c3e759d50da771f Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Mon, 4 May 2015 22:41:32 +0300 Subject: obj: Handle user instance hash based on Python adhoc rules. User instances are hashable by default (using __hash__ inherited from "object"). But if __eq__ is defined and __hash__ not defined in particular class, instance is not hashable. --- tests/basics/builtin_hash.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'tests') diff --git a/tests/basics/builtin_hash.py b/tests/basics/builtin_hash.py index 0abfe980e..d7615c3ec 100644 --- a/tests/basics/builtin_hash.py +++ b/tests/basics/builtin_hash.py @@ -19,3 +19,16 @@ class A: print(hash(A())) print({A():1}) + +class B: + pass +hash(B()) + + +class C: + def __eq__(self, another): + return True +try: + hash(C()) +except TypeError: + print("TypeError") -- cgit v1.2.3