modbuiltins: Add NotImplemented builtin constant.
From https://docs.python.org/3/library/constants.html#NotImplemented :
"Special value which should be returned by the binary special methods
(e.g. __eq__(), __lt__(), __add__(), __rsub__(), etc.) to indicate
that the operation is not implemented with respect to the other type;
may be returned by the in-place binary special methods (e.g. __imul__(),
__iand__(), etc.) for the same purpose. Its truth value is true."
Some people however appear to abuse it to mean "no value" when None is
a legitimate value (don't do that).
diff --git a/py/modbuiltins.c b/py/modbuiltins.c
index 455e1cc..9b5bd4c 100644
--- a/py/modbuiltins.c
+++ b/py/modbuiltins.c
@@ -634,6 +634,9 @@
// built-in objects
{ MP_OBJ_NEW_QSTR(MP_QSTR_Ellipsis), (mp_obj_t)&mp_const_ellipsis_obj },
+ #if MICROPY_PY_BUILTINS_NOTIMPLEMENTED
+ { MP_OBJ_NEW_QSTR(MP_QSTR_NotImplemented), MP_OBJ_SENTINEL },
+ #endif
// built-in user functions
{ MP_OBJ_NEW_QSTR(MP_QSTR_abs), (mp_obj_t)&mp_builtin_abs_obj },
diff --git a/py/mpconfig.h b/py/mpconfig.h
index a5aacc8..560fdce 100644
--- a/py/mpconfig.h
+++ b/py/mpconfig.h
@@ -479,6 +479,11 @@
#define MICROPY_PY_BUILTINS_REVERSED (1)
#endif
+// Whether to define "NotImplemented" special constant
+#ifndef MICROPY_PY_BUILTINS_NOTIMPLEMENTED
+#define MICROPY_PY_BUILTINS_NOTIMPLEMENTED (0)
+#endif
+
// Whether to set __file__ for imported modules
#ifndef MICROPY_PY___FILE__
#define MICROPY_PY___FILE__ (1)
diff --git a/py/obj.c b/py/obj.c
index 81adbe3..1928fad 100644
--- a/py/obj.c
+++ b/py/obj.c
@@ -62,6 +62,14 @@
return;
}
#endif
+
+ #if MICROPY_PY_BUILTINS_NOTIMPLEMENTED
+ if (o_in == MP_OBJ_SENTINEL) {
+ mp_printf(print, "%q", MP_QSTR_NotImplemented);
+ return;
+ }
+ #endif
+
mp_obj_type_t *type = mp_obj_get_type(o_in);
if (type->print != NULL) {
type->print((mp_print_t*)print, o_in, kind);
diff --git a/py/qstrdefs.h b/py/qstrdefs.h
index 77277c0..5d0dc9d 100644
--- a/py/qstrdefs.h
+++ b/py/qstrdefs.h
@@ -115,6 +115,9 @@
Q(Ellipsis)
Q(StopIteration)
+#if MICROPY_PY_BUILTINS_NOTIMPLEMENTED
+Q(NotImplemented)
+#endif
Q(BaseException)
Q(ArithmeticError)