diff --git a/py/modsys.c b/py/modsys.c index 12fa1101b94fc..451299d1add9f 100644 --- a/py/modsys.c +++ b/py/modsys.c @@ -293,6 +293,10 @@ STATIC const mp_rom_map_elem_t mp_module_sys_globals_table[] = { #endif #endif + #if MICROPY_PY_SYS_INTERN + { MP_ROM_QSTR(MP_QSTR_intern), MP_ROM_PTR(&mp_identity_obj) }, + #endif + #if MICROPY_PY_SYS_EXIT { MP_ROM_QSTR(MP_QSTR_exit), MP_ROM_PTR(&mp_sys_exit_obj) }, #endif diff --git a/py/mpconfig.h b/py/mpconfig.h index d14b1aa044533..b72004376b585 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -1434,6 +1434,12 @@ typedef double mp_float_t; #define MICROPY_PY_SYS_EXECUTABLE (0) #endif +// Whether to provide "sys.identity", implemented simply as returning the argument passed +// since strings are already interned as qstr. +#ifndef MICROPY_PY_SYS_INTERN +#define MICROPY_PY_SYS_INTERN (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EVERYTHING) +#endif + // Whether to provide "sys.exit" function #ifndef MICROPY_PY_SYS_EXIT #define MICROPY_PY_SYS_EXIT (1) diff --git a/tests/basics/sys1.py b/tests/basics/sys1.py index 759b9a6eaec22..594643a6d1b89 100644 --- a/tests/basics/sys1.py +++ b/tests/basics/sys1.py @@ -23,3 +23,8 @@ else: # Effectively skip subtests print(int) + +try: + print(sys.intern('micropython') == 'micropython') +except AttributeError: + print(True)