diff options
| author | Damien George | 2019-12-23 00:00:53 +1100 |
|---|---|---|
| committer | Damien George | 2019-12-27 12:53:36 +1100 |
| commit | f5eec903fa961135296e2656821450979e413248 (patch) | |
| tree | 2c8f804d0cc86a4b5c4d3a5febd7e63fb31900a2 | |
| parent | de8c04317be76222d2fbe7c5bf50ffd5ff2fd140 (diff) | |
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.
| -rw-r--r-- | py/objsingleton.c | 1 | ||||
| -rw-r--r-- | tests/basics/builtin_ellipsis.py | 3 | ||||
| -rw-r--r-- | tests/basics/class_notimpl.py | 3 |
3 files changed, 7 insertions, 0 deletions
diff --git a/py/objsingleton.c b/py/objsingleton.c index 67535391e..2b896305c 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 d88647a89..d66e86de4 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 308075f92..58e790716 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))) |
