py/objdict: Fix __hash__ for dict_view types.

This adds a unary_op implementation for the dict_view type that makes
the implementation of `hash()` for these types compatible with CPython.

Signed-off-by: David Lechner <david@pybricks.com>
This commit is contained in:
David Lechner
2023-01-18 13:59:54 -06:00
committed by Damien George
parent 8491eb190f
commit 2fe6d4eb86
2 changed files with 28 additions and 0 deletions

View File

@@ -18,4 +18,22 @@ try:
except TypeError:
print('TypeError')
# keys dict_view is not hashable
try:
hash({}.keys())
except TypeError:
print('TypeError')
# values dict_view is hashable
print(type(hash({}.values())))
# items dict_view is not hashable
try:
hash({}.items())
except TypeError:
print('TypeError')
# set operations still to come