diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2015-05-04 22:41:32 +0300 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2015-05-05 22:48:19 +0300 |
commit | 37c6555b4419eb6027a345ee0c3e759d50da771f (patch) | |
tree | 1a0d27a9b002c97380e7a185b38e7481908350a7 /tests/basics/builtin_hash.py | |
parent | 76677270218fb5732296e4fe1a0acbe05c8f818c (diff) |
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.
Diffstat (limited to 'tests/basics/builtin_hash.py')
-rw-r--r-- | tests/basics/builtin_hash.py | 13 |
1 files changed, 13 insertions, 0 deletions
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") |