A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
fix: syntax error handling in module reloading (#1222)
Akshay Agrawaldf208f35a1a7
diff --git a/marimo/_runtime/reload/autoreload.py b/marimo/_runtime/reload/autoreload.pyindex 82930253a1..d0d38435cb 100644--- a/marimo/_runtime/reload/autoreload.py+++ b/marimo/_runtime/reload/autoreload.py@@ -10,6 +10,7 @@ Based on the autoreload extension from the IPython project (BSD-3 Clause).from __future__ import annotationsimport gc+import ioimport osimport sysimport traceback@@ -21,6 +22,7 @@ from importlib.util import source_from_cachefrom typing import Any, Callable, Dict, Generic, List, Tuple, Type, TypeVarfrom marimo import _loggers+from marimo._messaging.tracebacks import write_tracebackLOGGER = _loggers.marimo_logger()@@ -312,10 +314,19 @@ def superreload(try:module = reload(module)- except:- # restore module dictionary on failed reload- if old_dict is not None:- module.__dict__.update(old_dict)+ except Exception as e:+ if isinstance(e, SyntaxError):+ # User introduced a SyntaxError -- they should be told,+ # and module dict should not be restored, ie don't fail+ # silently.+ tmpio = io.StringIO()+ traceback.print_exc(file=tmpio)+ tmpio.seek(0)+ write_traceback(tmpio.read())+ else:+ # restore module dictionary on failed reload+ if old_dict is not None:+ module.__dict__.update(old_dict)raise# iterate over all objects and update functions & classesdiff --git a/marimo/_runtime/reload/module_watcher.py b/marimo/_runtime/reload/module_watcher.pyindex f9891fd12c..043b2e657b 100644--- a/marimo/_runtime/reload/module_watcher.py+++ b/marimo/_runtime/reload/module_watcher.py@@ -65,9 +65,9 @@ def _depends_on(try:finder.run_script(src_module.__file__)except SyntaxError:- # user introduced a syntax error, maybe; don't- # exclude this module from future searches- return True+ # user introduced a syntax error, maybe; still check if the+ # module itself has been modified+ passexcept Exception:# some modules like numpy fail when called with run_script;# run_script takes a long time before failing on them, so