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: add '__class__' as a builtin (#6399)
Dylan Madisetti80fc3050d1f6
diff --git a/marimo/_ast/variables.py b/marimo/_ast/variables.pyindex 8f19a4efe6..e3bd269b10 100644--- a/marimo/_ast/variables.py+++ b/marimo/_ast/variables.py@@ -23,6 +23,13 @@ BUILTINS = set("__builtin__","__file__","__builtins__",+ # Only resolved in a class function, i.e.:+ # class A:+ # @staticmethod+ # def f():+ # (set(locals().keys()) - BUILTINS) == {'__class__'}+ # but promote to a global builtin for simplicity+ "__class__",})diff --git a/tests/_ast/test_toplevel.py b/tests/_ast/test_toplevel.pyindex 67100e0938..3b65ebb981 100644--- a/tests/_ast/test_toplevel.py+++ b/tests/_ast/test_toplevel.py@@ -2,8 +2,6 @@from __future__ import annotations-import builtins-from marimo._ast import toplevelfrom marimo._ast.app import App, InternalAppfrom marimo._ast.toplevel import (@@ -11,8 +9,7 @@ from marimo._ast.toplevel import (TopLevelStatus,TopLevelType,)--BUILTINS = set(builtins.__dict__.keys())+from marimo._ast.variables import BUILTINSclass TestTopLevelStatus:@@ -591,3 +588,16 @@ class TestTopLevelHook:TopLevelType.TOPLEVEL,TopLevelType.TOPLEVEL,] == [s.type for s in extraction], [s.hint for s in extraction]++ @staticmethod+ def test_class_builtin_ignored(app) -> None:+ @app.cell+ def cell():+ class Example:+ @staticmethod+ def method() -> None:+ print(__class__)+ return++ status = TopLevelStatus.from_cell(cell._cell, BUILTINS)+ assert status.type == TopLevelType.TOPLEVEL