From f5eec903fa961135296e2656821450979e413248 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 23 Dec 2019 00:00:53 +1100 Subject: [PATCH] py/objsingleton: Use mp_generic_unary_op for singleton objects. So these types more closely match NoneType, eg they can be hashed, like in CPython. --- py/objsingleton.c | 1 + tests/basics/builtin_ellipsis.py | 3 +++ tests/basics/class_notimpl.py | 3 +++ 3 files changed, 7 insertions(+) diff --git a/py/objsingleton.c b/py/objsingleton.c index 67535391ea..2b896305cf 100644 --- a/py/objsingleton.c +++ b/py/objsingleton.c @@ -47,6 +47,7 @@ const mp_obj_type_t mp_type_singleton = { { &mp_type_type }, .name = MP_QSTR_, .print = singleton_print, + .unary_op = mp_generic_unary_op, }; const mp_obj_singleton_t mp_const_ellipsis_obj = {{&mp_type_singleton}, MP_QSTR_Ellipsis}; diff --git a/tests/basics/builtin_ellipsis.py b/tests/basics/builtin_ellipsis.py index d88647a89a..d66e86de4a 100644 --- a/tests/basics/builtin_ellipsis.py +++ b/tests/basics/builtin_ellipsis.py @@ -4,3 +4,6 @@ print(...) print(Ellipsis) print(... == Ellipsis) + +# Test that Ellipsis can be hashed +print(type(hash(Ellipsis))) diff --git a/tests/basics/class_notimpl.py b/tests/basics/class_notimpl.py index 308075f92f..58e790716b 100644 --- a/tests/basics/class_notimpl.py +++ b/tests/basics/class_notimpl.py @@ -48,3 +48,6 @@ except TypeError: # NotImplemented isn't handled specially in unary methods print(-c) + +# Test that NotImplemented can be hashed +print(type(hash(NotImplemented)))