diff options
| author | David Lechner <david@pybricks.com> | 2023-01-18 13:59:54 -0600 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2023-05-19 12:06:17 +1000 |
| commit | 2fe6d4eb86a8496620a5db0958972ad5573932fb (patch) | |
| tree | 7b3db441a51da677356689ce2f92e87542bdd245 /tests/basics/dict_views.py | |
| parent | 8491eb190f2ea27f113c0cc7c0e619807a84f7ed (diff) | |
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>
Diffstat (limited to 'tests/basics/dict_views.py')
| -rw-r--r-- | tests/basics/dict_views.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/basics/dict_views.py b/tests/basics/dict_views.py index 7ebcc1f56..a82f47b6b 100644 --- a/tests/basics/dict_views.py +++ b/tests/basics/dict_views.py @@ -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 |
