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
chore: add PERF ruff rules (#3662)
Myles Scolnickebd8d84716ab
diff --git a/marimo/_ast/sql_visitor.py b/marimo/_ast/sql_visitor.pyindex bd6ba24c18..0c5f58368f 100644--- a/marimo/_ast/sql_visitor.py+++ b/marimo/_ast/sql_visitor.py@@ -373,7 +373,7 @@ def find_sql_refs()for scope in root.traverse(): # type: ignore- for _alias, (_node, source) in scope.selected_sources.items():+ for _node, source in scope.selected_sources.values():if isinstance(source, exp.Table):append_refs_from_table(source)diff --git a/marimo/_plugins/stateless/routes.py b/marimo/_plugins/stateless/routes.pyindex 97fa4e5d9b..64e73c6286 100644--- a/marimo/_plugins/stateless/routes.py+++ b/marimo/_plugins/stateless/routes.py@@ -63,7 +63,7 @@ class routes(UIElement[str, str]):) -> None:# For functions, wrap in lazychildren: list[Html] = []- for _, content in routes.items():+ for content in routes.values():if callable(content):children.append(lazy.lazy(content))else:diff --git a/marimo/_runtime/virtual_file.py b/marimo/_runtime/virtual_file.pyindex e13d5afe55..cae8420414 100644--- a/marimo/_runtime/virtual_file.py+++ b/marimo/_runtime/virtual_file.py@@ -271,7 +271,7 @@ class VirtualFileRegistry:returntry:self.shutting_down = True- for _, item in self.registry.items():+ for item in self.registry.values():if sys.platform == "win32":item.shm.close()item.shm.unlink()diff --git a/marimo/_server/sessions.py b/marimo/_server/sessions.pyindex 65dd8eee42..23cf3ce01f 100644--- a/marimo/_server/sessions.py+++ b/marimo/_server/sessions.py@@ -1016,7 +1016,7 @@ class SessionManager:alert = self.lsp_server.start()if alert is not None:- for _, session in self.sessions.items():+ for session in self.sessions.values():session.write_operation(alert, from_consumer_id=None)returndiff --git a/pyproject.toml b/pyproject.tomlindex 71616abeb1..9aeff506f8 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -165,6 +165,7 @@ dependencies = [[tool.hatch.envs.default.scripts]lint = "ruff check --fix"+lint-unsafe = "ruff check --fix --unsafe-fixes"format = "ruff format"[tool.hatch.envs.typecheck]@@ -305,8 +306,11 @@ exclude = [[tool.ruff.lint]ignore = ["G004", # Logging statement uses f-string- "TCH001", # Move application import into a type-checking block+ "TC001", # Move application import into a type-checking block"D301", # Use r""" if any backslashes in a docstring+ "PERF203", # try-except within a loop incurs performance overhead; not always possible+ "PERF401", # Use {message_str} to create a transformed list; at the cost of readability+ "PERF403", # Use a dictionary comprehension instead of a for-loop; at the cost of readability# TODO: we should fix these, and enable this rule"PT011", # `pytest.raises(ValueError)` is too broad, set the `match` parameter or use a more specific exception"E501", # Line too long, we still trim@@ -327,6 +331,7 @@ extend-select = ["ARG",# flake8-bugbear"B",+ "PERF","ANN002", # missing-type-args"ANN003", # missing-type-kwargs"ANN201", # missing-return-type-undocumented-public-functiondiff --git a/tests/_plugins/stateless/test_image.py b/tests/_plugins/stateless/test_image.pyindex 8a9cfc9b76..1bd8b3e806 100644--- a/tests/_plugins/stateless/test_image.py+++ b/tests/_plugins/stateless/test_image.py@@ -35,7 +35,7 @@ async def test_image_bytes_io(k: Kernel, exec_req: ExecReqProvider) -> None:])assert len(get_context().virtual_file_registry.registry) == 1- for fname, _ in get_context().virtual_file_registry.registry.items():+ for fname in get_context().virtual_file_registry.registry.keys():assert fname.endswith(".png")@@ -53,7 +53,7 @@ async def test_image_bytes(k: Kernel, exec_req: ExecReqProvider) -> None:])assert len(get_context().virtual_file_registry.registry) == 1- for fname, _ in get_context().virtual_file_registry.registry.items():+ for fname in get_context().virtual_file_registry.registry.keys():assert fname.endswith(".png")@@ -85,7 +85,7 @@ async def test_image_array(k: Kernel, exec_req: ExecReqProvider) -> None:])assert len(get_context().virtual_file_registry.registry) == 1- for fname, _ in get_context().virtual_file_registry.registry.items():+ for fname in get_context().virtual_file_registry.registry.keys():assert fname.endswith(".png")@@ -104,7 +104,7 @@ async def test_image_numpy(k: Kernel, exec_req: ExecReqProvider) -> None:])assert len(get_context().virtual_file_registry.registry) == 1- for fname, _ in get_context().virtual_file_registry.registry.items():+ for fname in get_context().virtual_file_registry.registry.keys():assert fname.endswith(".png")diff --git a/tests/_runtime/test_validate_graph.py b/tests/_runtime/test_validate_graph.pyindex 264578d39b..5ad9263208 100644--- a/tests/_runtime/test_validate_graph.py+++ b/tests/_runtime/test_validate_graph.py@@ -98,7 +98,7 @@ def test_three_node_cycle() -> None:graph.register_cell("2", parse_cell("z = x"))errors = check_for_errors(graph)assert set(errors.keys()) == set(["0", "1", "2"])- for _, t in errors.items():+ for t in errors.values():assert len(t) == 1assert isinstance(t[0], CycleError)edges_with_vars = t[0].edges_with_varsdiff --git a/tests/_runtime/test_virtual_file.py b/tests/_runtime/test_virtual_file.pyindex b240a5fc1c..9457f36163 100644--- a/tests/_runtime/test_virtual_file.py+++ b/tests/_runtime/test_virtual_file.py@@ -24,7 +24,7 @@ async def test_virtual_file_creation(])assert len(get_context().virtual_file_registry.registry) == 1- for fname, _ in get_context().virtual_file_registry.registry.items():+ for fname in get_context().virtual_file_registry.registry.keys():assert fname.endswith(".pdf")@@ -45,7 +45,7 @@ async def test_virtual_file_deletion(])assert len(get_context().virtual_file_registry.registry) == 1- for fname, _ in get_context().virtual_file_registry.registry.items():+ for fname in get_context().virtual_file_registry.registry.keys():assert fname.endswith(".pdf")await k.delete_cell(DeleteCellRequest(cell_id=er.cell_id))