Skip to content

Commit

Permalink
py/modsys: Implement sys.intern.
Browse files Browse the repository at this point in the history
Signed-off-by: stijn <[email protected]>
  • Loading branch information
stinos committed Dec 4, 2023
1 parent f3889db commit 4c9055b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions py/modsys.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions py/mpconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions tests/basics/sys1.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@
else:
# Effectively skip subtests
print(int)

try:
print(sys.intern('micropython') == 'micropython')
except AttributeError:
print(True)

0 comments on commit 4c9055b

Please sign in to comment.