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: patched `find_spec` should be a bound method (#764)
Akshay Agrawal92abd0c4bea8
diff --git a/marimo/_output/formatters/formatters.py b/marimo/_output/formatters/formatters.pyindex 260646876d..2015087acf 100644--- a/marimo/_output/formatters/formatters.py+++ b/marimo/_output/formatters/formatters.py@@ -80,11 +80,13 @@ def register_formatters() -> None:# to the new `find_spec` method; this is needed because closures are# late-binding and we're in a for loop ...def find_spec( # type:ignore[no-untyped-def]+ self,fullname,path=None,target=None,original_find_spec=original_find_spec,) -> Any:+ del selfspec = original_find_spec(fullname, path, target)if spec is None:return spec@@ -114,7 +116,9 @@ def register_formatters() -> None:return spec- finder.find_spec = find_spec # type: ignore[method-assign]+ # Use the __get__ descriptor to bind find_spec to this finder object,+ # to make sure self/cls gets passed+ finder.find_spec = find_spec.__get__(finder) # type: ignore[method-assign]# These factories are for builtins or other things that don't require a# package import. So we can register them at program start-up.diff --git a/tests/_output/formatters/test_formatters.py b/tests/_output/formatters/test_formatters.pynew file mode 100644index 0000000000..9609563d42--- /dev/null+++ b/tests/_output/formatters/test_formatters.py@@ -0,0 +1,16 @@+import importlib+import os.path++from marimo._output.formatters.formatters import register_formatters+++def test_path_finder_find_spec() -> None:+ # exercises a bug surfaced in+ # https://github.com/marimo-team/marimo/issues/763, in which find_spec+ # would fail because it was incorrectly patched+ register_formatters()++ spec = importlib.machinery.PathFinder.find_spec(+ "test_formatters", [os.path.dirname(__file__)]+ )+ assert spec is not None