micropython/py
David Grayson a79a6ab364 py/builtinimport: Remove partially-loaded modules from sys.modules.
Prior to this commit, importing a module that exists but has a syntax error
or some other problem that happens at import time would result in a
potentially-incomplete module object getting added to sys.modules.
Subsequent imports would use that object, resulting in confusing error
messages that hide the root cause of the problem.

This commit fixes that issue by removing the failed module from sys.modules
using the new NLR callback mechanism.

Note that it is still important to add the module to sys.modules while the
import is happening so that we can support circular imports just like
CPython does.

Fixes issue #967.

Signed-off-by: David Grayson <davidegrayson@gmail.com>
2023-06-05 23:21:52 +10:00
..
argcheck.c py: Remove the word "yet" from exception messages. 2022-12-06 13:34:52 +11:00
asmarm.c py/asmarm: Add asm_arm_ldrh_reg_reg_offset() helper func. 2022-05-23 14:21:16 +10:00
asmarm.h py/asm: Add ASM_LOAD16_REG_REG_OFFSET macro for load-u16 with offset. 2022-05-23 14:21:16 +10:00
asmbase.c all: Fix spelling mistakes based on codespell check. 2023-04-27 18:03:06 +10:00
asmbase.h py/emit: Suppress unreachable bytecode/native code that follows jump. 2022-06-20 22:28:18 +10:00
asmthumb.c all: Fix spelling mistakes based on codespell check. 2023-04-27 18:03:06 +10:00
asmthumb.h py/asmthumb: Make ARMv7-M instruction use dynamically selectable. 2022-05-23 23:01:12 +10:00
asmx64.c py/asmx64: Support full range of regs in asm_x64_lea_disp_to_r64. 2022-05-17 14:25:51 +10:00
asmx64.h py/asm: Add ASM_LOAD16_REG_REG_OFFSET macro for load-u16 with offset. 2022-05-23 14:21:16 +10:00
asmx86.c py/asm: Add funcs/macros to emit machine code for logical-shift-right. 2020-06-27 00:24:04 +10:00
asmx86.h py/asm: Add ASM_LOAD16_REG_REG_OFFSET macro for load-u16 with offset. 2022-05-23 14:21:16 +10:00
asmxtensa.c py/asmxtensa: Fix use of l32i/s32i when offset won't fit in encoding. 2022-03-30 16:32:17 +11:00
asmxtensa.h py/asm: Add ASM_LOAD16_REG_REG_OFFSET macro for load-u16 with offset. 2022-05-23 14:21:16 +10:00
bc.c py/bc: Fix checking for duplicate **kwargs. 2022-11-28 11:23:22 +11:00
bc.h py: Pass in address to compiled module instead of returning it. 2022-12-08 12:27:23 +11:00
bc0.h py: Change jump-if-x-or-pop opcodes to have unsigned offset argument. 2022-03-28 15:43:09 +11:00
binary.c py: Clean up formatting of union definitions. 2022-08-23 13:09:57 +10:00
binary.h py/binary: Change mp_uint_t to size_t for index, size, align args. 2019-09-02 13:14:27 +10:00
builtin.h py/builtinimport: Allow overriding of mp_builtin___import__. 2022-08-23 13:34:06 +10:00
builtinevex.c py: Use nlr jump callbacks to optimise compile/execute functions. 2023-06-02 21:59:47 +10:00
builtinhelp.c py/obj: Add accessors for type slots and use everywhere. 2022-09-19 19:06:07 +10:00
builtinimport.c py/builtinimport: Remove partially-loaded modules from sys.modules. 2023-06-05 23:21:52 +10:00
compile.c py/compile: Remove over-eager optimisation of tuples as if condition. 2023-05-03 13:21:18 +10:00
compile.h py: Pass in address to compiled module instead of returning it. 2022-12-08 12:27:23 +11:00
dynruntime.h py/obj: Convert make_new into a mp_obj_type_t slot. 2022-09-19 19:06:15 +10:00
dynruntime.mk py/dynruntime.mk: Allow building assembly source in natmods. 2022-08-11 14:00:13 +10:00
emit.h py/compile: Fix scope of assignment expression target in comprehensions. 2023-03-09 12:13:12 +11:00
emitbc.c all: Fix spelling mistakes based on codespell check. 2023-04-27 18:03:06 +10:00
emitcommon.c py/compile: Fix scope of assignment expression target in comprehensions. 2023-03-09 12:13:12 +11:00
emitglue.c py/emitnative: Access qstr values using indirection table qstr_table. 2022-05-23 15:43:06 +10:00
emitglue.h py/emitnative: Access qstr values using indirection table qstr_table. 2022-05-23 15:43:06 +10:00
emitinlinethumb.c py/emitinlinethumb: Make float instruction use dynamically selectable. 2022-05-26 12:22:07 +10:00
emitinlinextensa.c py: Use unsigned comparison of chars. 2020-10-22 11:47:36 +02:00
emitnarm.c py/emitnative: Access qstr values using indirection table qstr_table. 2022-05-23 15:43:06 +10:00
emitnative.c all: Fix spelling mistakes based on codespell check. 2023-04-27 18:03:06 +10:00
emitnthumb.c py/emitnative: Access qstr values using indirection table qstr_table. 2022-05-23 15:43:06 +10:00
emitnx64.c py/emitnative: Access qstr values using indirection table qstr_table. 2022-05-23 15:43:06 +10:00
emitnx86.c py/emitnative: Access qstr values using indirection table qstr_table. 2022-05-23 15:43:06 +10:00
emitnxtensa.c py/emitnative: Access qstr values using indirection table qstr_table. 2022-05-23 15:43:06 +10:00
emitnxtensawin.c py/emitnative: Access qstr values using indirection table qstr_table. 2022-05-23 15:43:06 +10:00
formatfloat.c all: Fix spelling mistakes based on codespell check. 2023-04-27 18:03:06 +10:00
formatfloat.h all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
frozenmod.c py: Rework bytecode and .mpy file format to be mostly static data. 2022-02-24 18:08:43 +11:00
frozenmod.h py/builtin: Clean up and simplify import_stat and builtin_open config. 2022-05-25 13:04:45 +10:00
gc.c py/gc: Make improvements to MICROPY_GC_HOOK_LOOP. 2023-05-09 12:44:14 +10:00
gc.h py/gc: Make gc_dump_info/gc_dump_alloc_table take a printer as argument. 2023-03-10 10:58:10 +11:00
grammar.h py/compile: Implement PEP 526, syntax for variable annotations. 2020-06-16 23:18:01 +10:00
lexer.c py/lexer: Wrap in parenthesis all f-string arguments passed to format. 2023-01-20 17:54:32 +11:00
lexer.h py/builtin: Clean up and simplify import_stat and builtin_open config. 2022-05-25 13:04:45 +10:00
make_root_pointers.py py/make_root_pointers: Add MP_REGISTER_ROOT_POINTER parser/generator. 2022-07-18 13:48:23 +10:00
makecompresseddata.py all: Fix spelling mistakes based on codespell check. 2023-04-27 18:03:06 +10:00
makemoduledefs.py py/makemoduledefs.py: Emit useful error for legacy MP_REGISTER_MODULE. 2022-06-14 15:05:37 +01:00
makeqstrdata.py top: Update Python formatting to black "2023 stable style". 2023-02-02 12:51:03 +11:00
makeqstrdefs.py py/makeqstrdefs.py: Fix handling GreenHills C/C++ preprocessor output. 2023-04-11 16:41:10 +10:00
makeversionhdr.py py/makeversionhdr.py: Always add micro to version string even if it's 0. 2023-03-10 18:39:14 +11:00
malloc.c py/malloc: Introduce m_tracked_calloc, m_tracked_free functions. 2022-05-05 10:31:50 +10:00
map.c py/map: Clear value when re-using slot with ordered dictionaries. 2023-01-13 14:21:32 +11:00
misc.h py/misc: Remove use of bitfield from vstr_t. 2022-10-12 00:33:09 +11:00
mkenv.mk py/mkenv.mk: Make CPP definition explicit for consistency. 2022-09-29 14:17:37 +02:00
mkrules.cmake py/mkrules.cmake: Force build mpversion.h and frozen_content.c. 2023-02-08 12:24:15 +11:00
mkrules.mk all: Fix spelling mistakes based on codespell check. 2023-04-27 18:03:06 +10:00
modarray.c all: Remove third argument to MP_REGISTER_MODULE. 2022-06-02 16:31:37 +10:00
modbuiltins.c all: Fix spelling mistakes based on codespell check. 2023-04-27 18:03:06 +10:00
modcmath.c all: Remove third argument to MP_REGISTER_MODULE. 2022-06-02 16:31:37 +10:00
modcollections.c all: Remove third argument to MP_REGISTER_MODULE. 2022-06-02 16:31:37 +10:00
modgc.c all: Remove third argument to MP_REGISTER_MODULE. 2022-06-02 16:31:37 +10:00
modio.c py/obj: Convert make_new into a mp_obj_type_t slot. 2022-09-19 19:06:15 +10:00
modmath.c py/modmath: Fix two-argument math function domain check. 2023-02-24 15:55:12 +11:00
modmicropython.c py/gc: Make gc_dump_info/gc_dump_alloc_table take a printer as argument. 2023-03-10 10:58:10 +11:00
modstruct.c py/objstr: Split mp_obj_str_from_vstr into bytes/str versions. 2022-08-26 16:43:55 +10:00
modsys.c py/modsys: Add support for sys.executable. 2022-10-11 18:10:26 +11:00
modthread.c py/obj: Convert make_new into a mp_obj_type_t slot. 2022-09-19 19:06:15 +10:00
moduerrno.c all: Remove third argument to MP_REGISTER_MODULE. 2022-06-02 16:31:37 +10:00
mpconfig.h py/objmodule: Don't use sys.modules to track a builtin __init__. 2023-06-01 16:21:37 +10:00
mperrno.h py/mperrno: Add MP_ECANCELED error code. 2021-06-24 23:14:01 +10:00
mphal.h all: Rename absolute time-based functions to include "epoch". 2020-09-18 17:20:34 +10:00
mpprint.c py/mpprint: Fix length calculation for strings with precision-modifier. 2020-12-07 23:32:06 +11:00
mpprint.h py/mpprint: Fix formatting typo with mp_print_ext_t struct name. 2022-08-10 14:30:47 +10:00
mpstate.c all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
mpstate.h py/nlr: Implement jump callbacks. 2023-06-02 21:50:57 +10:00
mpthread.h all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
mpz.c py/mpz: Fix bugs with bitwise of -0 by ensuring all 0's are positive. 2021-12-21 18:00:05 +11:00
mpz.h py/mpz: Fix bugs with bitwise of -0 by ensuring all 0's are positive. 2021-12-21 18:00:05 +11:00
nativeglue.c py/bc: Provide separate code-state setup funcs for bytecode and native. 2022-05-17 14:25:51 +10:00
nativeglue.h py/bc: Provide separate code-state setup funcs for bytecode and native. 2022-05-17 14:25:51 +10:00
nlr.c py/nlr: Implement jump callbacks. 2023-06-02 21:50:57 +10:00
nlr.h py/nlr: Implement jump callbacks. 2023-06-02 21:50:57 +10:00
nlraarch64.c py/nlraarch64: Add underscore prefix to function symbols for Darwin ABI. 2021-05-18 11:46:30 +10:00
nlrmips.c py/nlrmips: Add native NLR support for MIPS architecture. 2022-11-15 17:09:49 +11:00
nlrpowerpc.c py/nlrpowerpc: Fix generation of ppc64 code on ppc32 build. 2022-08-11 14:04:13 +10:00
nlrsetjmp.c py/nlrsetjmp: Use MP_NLR_JUMP_HEAD macro to simplify code. 2023-06-02 21:47:34 +10:00
nlrthumb.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
nlrx64.c py/nlrx64: Correct the detection of Darwin ABI. 2021-05-18 11:52:00 +10:00
nlrx86.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
nlrxtensa.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
obj.c py/obj: Accept user types in mp_obj_get_int_maybe. 2023-06-01 14:18:54 +10:00
obj.h py/builtinimport: Optimise sub-package loading. 2023-06-01 16:21:21 +10:00
objarray.c py/objarray: Disallow memoryview addition. 2023-05-19 13:33:54 +10:00
objarray.h py/objarray: Raise error on out-of-bound memoryview slice start. 2023-01-20 16:31:37 +11:00
objattrtuple.c py/obj: Convert make_new into a mp_obj_type_t slot. 2022-09-19 19:06:15 +10:00
objbool.c py/obj: Convert make_new into a mp_obj_type_t slot. 2022-09-19 19:06:15 +10:00
objboundmeth.c py/obj: Convert make_new into a mp_obj_type_t slot. 2022-09-19 19:06:15 +10:00
objcell.c py/obj: Convert make_new into a mp_obj_type_t slot. 2022-09-19 19:06:15 +10:00
objclosure.c py/obj: Convert make_new into a mp_obj_type_t slot. 2022-09-19 19:06:15 +10:00
objcomplex.c py/obj: Convert make_new into a mp_obj_type_t slot. 2022-09-19 19:06:15 +10:00
objdeque.c py/obj: Convert make_new into a mp_obj_type_t slot. 2022-09-19 19:06:15 +10:00
objdict.c py/objdict: Fix __hash__ for dict_view types. 2023-05-19 12:06:17 +10:00
objenumerate.c py/obj: Convert make_new into a mp_obj_type_t slot. 2022-09-19 19:06:15 +10:00
objexcept.c all: Fix spelling mistakes based on codespell check. 2023-04-27 18:03:06 +10:00
objexcept.h py/obj: Convert make_new into a mp_obj_type_t slot. 2022-09-19 19:06:15 +10:00
objfilter.c py/obj: Convert make_new into a mp_obj_type_t slot. 2022-09-19 19:06:15 +10:00
objfloat.c py/obj: Convert make_new into a mp_obj_type_t slot. 2022-09-19 19:06:15 +10:00
objfun.c py/obj: Remove mp_generic_unary_op(). 2023-05-19 12:04:44 +10:00
objfun.h py: Rework bytecode and .mpy file format to be mostly static data. 2022-02-24 18:08:43 +11:00
objgenerator.c py/obj: Remove mp_generic_unary_op(). 2023-05-19 12:04:44 +10:00
objgenerator.h all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
objgetitemiter.c py/obj: Convert make_new into a mp_obj_type_t slot. 2022-09-19 19:06:15 +10:00
objint.c py/objint: Allow int() to parse anything with the buffer protocol. 2023-06-01 15:11:06 +10:00
objint.h py/modsys: Use consistent naming pattern for module-level const objects. 2020-05-28 10:02:14 +10:00
objint_longlong.c py: Change MP_UNARY_OP_INT to MP_UNARY_OP_INT_MAYBE. 2023-06-01 13:01:07 +10:00
objint_mpz.c py: Change MP_UNARY_OP_INT to MP_UNARY_OP_INT_MAYBE. 2023-06-01 13:01:07 +10:00
objlist.c py/obj: Convert make_new into a mp_obj_type_t slot. 2022-09-19 19:06:15 +10:00
objlist.h py/obj: Convert make_new into a mp_obj_type_t slot. 2022-09-19 19:06:15 +10:00
objmap.c py/obj: Convert make_new into a mp_obj_type_t slot. 2022-09-19 19:06:15 +10:00
objmodule.c py/objmodule: Don't use sys.modules to track a builtin __init__. 2023-06-01 16:21:37 +10:00
objmodule.h py/builtinimport: Optimise sub-package loading. 2023-06-01 16:21:21 +10:00
objnamedtuple.c py/obj: Convert make_new into a mp_obj_type_t slot. 2022-09-19 19:06:15 +10:00
objnamedtuple.h py/obj: Convert make_new into a mp_obj_type_t slot. 2022-09-19 19:06:15 +10:00
objnone.c py/obj: Remove mp_generic_unary_op(). 2023-05-19 12:04:44 +10:00
objobject.c py/obj: Convert make_new into a mp_obj_type_t slot. 2022-09-19 19:06:15 +10:00
objpolyiter.c py/obj: Convert make_new into a mp_obj_type_t slot. 2022-09-19 19:06:15 +10:00
objproperty.c py/obj: Convert make_new into a mp_obj_type_t slot. 2022-09-19 19:06:15 +10:00
objrange.c py/obj: Convert make_new into a mp_obj_type_t slot. 2022-09-19 19:06:15 +10:00
objreversed.c py/obj: Convert make_new into a mp_obj_type_t slot. 2022-09-19 19:06:15 +10:00
objset.c py/obj: Convert make_new into a mp_obj_type_t slot. 2022-09-19 19:06:15 +10:00
objsingleton.c py/obj: Remove mp_generic_unary_op(). 2023-05-19 12:04:44 +10:00
objslice.c py/objslice: Ensure slice is not hashable. 2023-05-19 12:06:06 +10:00
objstr.c py/objstr: Return unsupported binop instead of raising TypeError. 2023-05-19 13:42:35 +10:00
objstr.h py/objstr: Add a helper to set mp_obj_str_t data. 2022-10-11 17:50:19 +11:00
objstringio.c py/obj: Convert make_new into a mp_obj_type_t slot. 2022-09-19 19:06:15 +10:00
objstringio.h py/objstringio: If created from immutable object, follow copy on write policy. 2017-06-09 17:33:01 +03:00
objstrunicode.c py/obj: Convert make_new into a mp_obj_type_t slot. 2022-09-19 19:06:15 +10:00
objtuple.c py/obj: Convert make_new into a mp_obj_type_t slot. 2022-09-19 19:06:15 +10:00
objtuple.h all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
objtype.c py: Change MP_UNARY_OP_INT to MP_UNARY_OP_INT_MAYBE. 2023-06-01 13:01:07 +10:00
objtype.h py/obj: Optimise code size and performance for make_new as a slot. 2022-09-19 19:06:16 +10:00
objzip.c py/obj: Convert make_new into a mp_obj_type_t slot. 2022-09-19 19:06:15 +10:00
opmethods.c py/obj: Add accessors for type slots and use everywhere. 2022-09-19 19:06:07 +10:00
pairheap.c py/pairheap: Properly unlink node on pop and delete. 2020-03-26 01:21:04 +11:00
pairheap.h py/pairheap: Add helper function to initialise a new node. 2020-03-26 01:21:04 +11:00
parse.c py/parse: Fix build when COMP_CONST_FOLDING=0 and COMP_MODULE_CONST=1. 2023-05-03 13:12:54 +10:00
parse.h py/parse: Factor obj extract code to mp_parse_node_extract_const_object. 2022-04-14 22:44:56 +10:00
parsenum.c py/objstr: Optimise mp_obj_new_str_from_vstr for known-safe strings. 2022-08-26 16:44:35 +10:00
parsenum.h py/parsenum: Optimise when building with complex disabled. 2022-06-23 11:46:47 +10:00
parsenumbase.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
parsenumbase.h all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
persistentcode.c py: Pass in address to compiled module instead of returning it. 2022-12-08 12:27:23 +11:00
persistentcode.h py: Pass in address to compiled module instead of returning it. 2022-12-08 12:27:23 +11:00
profile.c py/obj: Remove mp_generic_unary_op(). 2023-05-19 12:04:44 +10:00
profile.h py: Rework bytecode and .mpy file format to be mostly static data. 2022-02-24 18:08:43 +11:00
py.cmake py/nlrmips: Add native NLR support for MIPS architecture. 2022-11-15 17:09:49 +11:00
py.mk py/nlrmips: Add native NLR support for MIPS architecture. 2022-11-15 17:09:49 +11:00
pystack.c py: Introduce and use mp_raise_type_arg helper. 2021-07-15 00:12:41 +10:00
pystack.h all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
qstr.c py/qstr: Change qstr hash type from mp_uint_t to size_t. 2022-08-11 23:18:02 +10:00
qstr.h py/qstr: Change qstr hash type from mp_uint_t to size_t. 2022-08-11 23:18:02 +10:00
qstrdefs.h py/modsys: Add optional mutable attributes sys.ps1/ps2 and use them. 2022-03-10 10:58:33 +11:00
reader.c py: Include filename in errors from loading/saving files via "open". 2022-09-19 23:27:08 +10:00
reader.h py: Allow lexer to raise exceptions during construction. 2017-03-14 11:52:05 +11:00
repl.c shared/readline: Make tab insert an indent when it follows whitespace. 2022-04-22 17:00:16 +10:00
repl.h py/modsys: Add optional mutable attributes sys.ps1/ps2 and use them. 2022-03-10 10:58:33 +11:00
ringbuf.c py/ringbuf: Implement put_bytes/get_bytes functions. 2023-05-01 16:47:03 +10:00
ringbuf.h py/ringbuf: Implement put_bytes/get_bytes functions. 2023-05-01 16:47:03 +10:00
runtime.c py: Use nlr jump callbacks to optimise compile/execute functions. 2023-06-02 21:59:47 +10:00
runtime.h py: Use nlr jump callbacks to optimise compile/execute functions. 2023-06-02 21:59:47 +10:00
runtime0.h py: Change MP_UNARY_OP_INT to MP_UNARY_OP_INT_MAYBE. 2023-06-01 13:01:07 +10:00
runtime_utils.c py: mp_call_function_*_protected(): Pass-thru return value if possible. 2017-12-05 00:38:41 +02:00
scheduler.c py/scheduler: Implement VM abort flag and mp_sched_vm_abort(). 2023-03-21 18:08:57 +11:00
scope.c py: Rework bytecode and .mpy file format to be mostly static data. 2022-02-24 18:08:43 +11:00
scope.h all: Fix spelling mistakes based on codespell check. 2023-04-27 18:03:06 +10:00
sequence.c all: Fix spelling mistakes based on codespell check. 2023-04-27 18:03:06 +10:00
showbc.c py: Change jump-if-x-or-pop opcodes to have unsigned offset argument. 2022-03-28 15:43:09 +11:00
smallint.c all: Use the name MicroPython consistently in comments 2017-07-31 18:35:40 +10:00
smallint.h py/smallint: Introduce MP_SMALL_INT_BITS macro. 2022-03-25 12:23:43 +11:00
stackctrl.c py/stackctrl: Add gcc pragmas to ignore dangling-pointer warning. 2023-05-04 10:08:12 +10:00
stackctrl.h py/stackctrl: Prevent unused-var warning when stack checking disabled. 2021-06-05 11:03:09 +10:00
stream.c py/obj: Add accessors for type slots and use everywhere. 2022-09-19 19:06:07 +10:00
stream.h py/obj: Add accessors for type slots and use everywhere. 2022-09-19 19:06:07 +10:00
unicode.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
unicode.h py/objstr: Add check for valid UTF-8 when making a str from bytes. 2017-09-06 16:43:09 +10:00
usermod.cmake rp2: Add support for USER_C_MODULES to CMake build system. 2021-03-31 00:26:01 +11:00
vm.c py/scheduler: Implement VM abort flag and mp_sched_vm_abort(). 2023-03-21 18:08:57 +11:00
vmentrytable.h py/vmentrytable: Ignore GCC -Woverride-init. 2020-10-22 11:47:36 +02:00
vstr.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
warning.c py: Update my copyright info on some files. 2019-02-06 00:19:00 +11:00