summaryrefslogtreecommitdiffstatshomepage
path: root/tests/basics
diff options
context:
space:
mode:
authorDavid Lechner <david@pybricks.com>2023-01-18 13:59:54 -0600
committerDamien George <damien@micropython.org>2023-05-19 12:06:17 +1000
commit2fe6d4eb86a8496620a5db0958972ad5573932fb (patch)
tree7b3db441a51da677356689ce2f92e87542bdd245 /tests/basics
parent8491eb190f2ea27f113c0cc7c0e619807a84f7ed (diff)
downloadmicropython-2fe6d4eb86a8496620a5db0958972ad5573932fb.tar.gz
micropython-2fe6d4eb86a8496620a5db0958972ad5573932fb.zip
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')
-rw-r--r--tests/basics/dict_views.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/basics/dict_views.py b/tests/basics/dict_views.py
index 7ebcc1f56d..a82f47b6be 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