Skip to content

additional ruff fixes#9132

Merged
mscolnick merged 13 commits into
mainfrom
sham/additional-ruff-fixes
Apr 10, 2026
Merged

additional ruff fixes#9132
mscolnick merged 13 commits into
mainfrom
sham/additional-ruff-fixes

Conversation

@Light2Dark

@Light2Dark Light2Dark commented Apr 10, 2026

Copy link
Copy Markdown
Member

📝 Summary

Most of these are ruff autofixes, which can be done with ruff check --unsafe-fixes --fix. I removed ones that were safe with AI help.

I then went in again with Claude, and GPT to review the PR, and offer cleanup of the code. These are the last commits.

📋 Pre-Review Checklist

  • For large changes, or changes that affect the public API: this change was discussed or approved through an issue, on Discord, or the community discussions (Please provide a link if applicable).
  • Any AI generated code has been reviewed line-by-line by the human PR author, who stands by it.
  • Video or media evidence is provided for any visual changes (optional).

✅ Merge Checklist

  • I have read the contributor guidelines.
  • Documentation has been updated where applicable, including docstrings for API changes.
  • Tests have been added for the changes made.

@vercel

vercel Bot commented Apr 10, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview, Comment Apr 10, 2026 6:05pm

Request Review

@Light2Dark Light2Dark requested a review from Copilot April 10, 2026 17:27
@Light2Dark Light2Dark added the internal A refactor or improvement that is not user facing label Apr 10, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR applies a broad set of Ruff-driven refactors across the marimo Python codebase and its test suite, primarily to satisfy newly-enabled (or no-longer-ignored) lint rules. The changes are largely mechanical (container literals, comprehension simplifications, raise usage, startswith/endswith tuples, iterating dicts directly, etc.) and intended to reduce lint noise and improve consistency.

Changes:

  • Refactor many Python expressions to preferred idioms (e.g., {...}/(...)/{k: v} literals, set/dict comprehensions, next(iter(...)), direct dict iteration, tuple-form startswith/endswith).
  • Replace raise e with bare raise in exception handlers to preserve tracebacks.
  • Update Ruff configuration (pyproject.toml) by removing several ignores now that corresponding violations have been addressed.

Reviewed changes

Copilot reviewed 132 out of 132 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/_utils/test_parse_dataclass.py Use tuple literal instead of tuple([...]) in test data.
tests/_utils/test_health_utils.py Use list literal [] instead of list() in tests.
tests/_utils/test_formatter.py Iterate dict directly rather than .keys() in tests.
tests/_utils/test_flatten.py Replace unnecessary tuple()/dict() calls with literals in tests.
tests/_sql/test_sql_parse.py Rename unused error binding to _error in tests.
tests/_session/test_file_change_handler.py Replace list(...)[0] with next(iter(...)) in tests.
tests/_session/state/test_serialize_session.py Use empty tuple literal () in cache key construction.
tests/_server/test_file_manager.py Replace list(...)[0] with next(iter(...)) in tests.
tests/_server/test_asgi.py Use tuple-form .endswith((...)) in tests.
tests/_server/api/endpoints/test_ws.py Replace list(...)[0] with next(iter(...)) in tests.
tests/_server/api/endpoints/test_execution.py Iterate dict directly instead of .keys() in tests.
tests/_server/ai/test_mcp.py Fix implicit-optional type hints and unused variables in tests.
tests/_save/test_cache.py Use bare raise; rename unused state/set_state where appropriate.
tests/_save/store/test_store.py Prefer key in dict over key in dict.keys() in tests.
tests/_runtime/test_virtual_file.py Iterate dict/set-like containers directly; avoid list(...)[0] in tests.
tests/_runtime/test_runtime.py Prefer set literals and generator forms over unnecessary allocations in tests.
tests/_runtime/test_edges.py Rename unused tuple unpack members to _children/_parents in tests.
tests/_runtime/test_dataflow.py Prefer set literals/comprehensions over set([...]) in tests.
tests/_runtime/test_control_flow.py Prefer set literal over set([...]) in tests.
tests/_runtime/test_complete.py Fix bug: actually raise RuntimeError(...) in test helper logic.
tests/_runtime/reload/test_autoreload.py Avoid redundant list(set(list(...))) patterns in tests.
tests/_runtime/packages/test_module_registry.py Prefer set literal over set([...]) in tests.
tests/_pyodide/test_bootstrap.py Rename unused session binding to _session in tests.
tests/_plugins/ui/_impl/test_table.py Prefer set literal {...} in invalid-data test case.
tests/_plugins/ui/_impl/tables/test_polars_table.py Prefer set literals in complex-data fixtures.
tests/_plugins/ui/_impl/tables/test_pandas_table.py Prefer set literals in complex-data fixtures.
tests/_plugins/ui/_impl/tables/test_narwhals.py Prefer set literals in complex-data fixtures.
tests/_plugins/ui/_impl/dataframes/test_dataframe.py Simplify boolean-return helper for narwhals detection in tests.
tests/_plugins/ui/_impl/charts/test_altair_transformers.py Use tuple-form .startswith((...)) in tests.
tests/_plugins/ui/_core/test_registry.py Prefer set literals in assertions.
tests/_plugins/stateless/test_image.py Iterate registry dict directly instead of .keys() in tests.
tests/_plugins/stateless/test_image_compare.py Iterate registry dict directly instead of .keys() in tests.
tests/_plugins/stateless/test_audio.py Iterate registry dict directly instead of .keys() in tests.
tests/_plugins/core/test_json_encoder.py Prefer set literals in set-encoding tests.
tests/_output/test_try_format.py Prefer set literal in formatting test.
tests/_output/formatters/test_sympy.py Rename unused symbol bindings to _y/_z in tests.
tests/_output/formatters/test_structures.py Rename unused data binding to _data; prefer () literal in tests.
tests/_output/formatters/test_ibis_formatters.py Prefer dict literal over dict(...) in ibis schema construction tests.
tests/_messaging/test_variables.py Prefer () literal over tuple() in tests.
tests/_lint/test_validate_graph.py Prefer set literals in assertions.
tests/_data/mocks.py Simplify boolean-return helper in test mock generation.
tests/_ast/test_visitor.py Prefer literals and simplify string building in tests.
tests/_ast/test_compiler.py Prefer set literals; avoid list(...)[0] by using next(iter(...)) in tests.
tests/_ast/test_codegen.py Simplify string assembly; prefer tuple literals.
tests/_ast/test_cell.py Prefer set literal in assertions.
tests/_ai/llm/test_impl.py Rename unused mock client bindings in tests.
pyproject.toml Remove several Ruff ignores now that violations are fixed; keep Ruff scope/excludes intact.
marimo/_utils/site_packages.py Use tuple-form .endswith((...)); simplify boolean return.
marimo/_utils/narwhals_utils.py Use tuple-form isinstance(..., (...)) for narwhals type checks.
marimo/_utils/inline_script_metadata.py Simplify suffix checks; consolidate dependency-prefix matching with tuple .startswith.
marimo/_utils/format_signature.py Use tuple-form .startswith((...)).
marimo/_utils/distributor.py Fix Protocol/Generic base ordering for typing correctness.
marimo/_utils/dataclass_to_openapi.py Reorder docstring sections to match conventions.
marimo/_utils/async_path.py Use Self return annotation (with postponed evaluation) for __new__.
marimo/_sql/utils.py Use tuple-form .startswith((...)) for comment detection.
marimo/_snippets/snippets.py Use tuple-form .startswith((...)).
marimo/_session/state/session_view.py Prefer set comprehension literal over set([...]).
marimo/_session/state/serialize.py Simplify boolean-return logic in cache-hit check.
marimo/_server/utils.py Remove unused re-export-style import.
marimo/_server/export/_live_notebook_server.py Use Self in __enter__ return annotation.
marimo/_server/export/_html_asset_server.py Use Self in __enter__ return annotation.
marimo/_server/errors.py Simplify accept-header check to direct boolean return.
marimo/_server/api/middleware.py Replace raise e with bare raise; simplify redundant exception handling.
marimo/_server/api/endpoints/ws/ws_message_loop.py Replace raise e with bare raise to preserve traceback.
marimo/_server/ai/providers.py Simplify boolean logic in reasoning-model detection.
marimo/_server/ai/mcp/client.py Iterate dict directly instead of .keys(); simplify list comprehension over dict.
marimo/_server/ai/mcp/init.py Reorder __all__ entries without functional change.
marimo/_server/ai/ids.py Use tuple-form .startswith((...)) for provider inference.
marimo/_save/stores/redis.py Simplify boolean return for put.
marimo/_save/save.py Prefer set comprehension literal; replace raise e with bare raise.
marimo/_save/loaders/loader.py Simplify string construction for error message.
marimo/_save/hash.py Use discard for set removal; prefer set comprehension literal.
marimo/_save/cache.py Prefer set comprehensions for set conversion/restore paths.
marimo/_runtime/watch/_directory.py Prefer set comprehension literal over set(generator).
marimo/_runtime/virtual_file/storage.py Use Self return annotation for singleton __new__.
marimo/_runtime/virtual_file/init.py Reorder __all__ entries without functional change.
marimo/_runtime/runtime.py Prefer () empty tuple; prefer .get over membership+index; simplify boolean fields and loops.
marimo/_runtime/runner/hooks_post_execution.py Prefer set comprehension literal; simplify .get usage.
marimo/_runtime/runner/cell_runner.py Simplify traceback decision; prefer set literal/comprehension; simplify dict .get.
marimo/_runtime/reload/module_watcher.py Prefer set comprehensions and direct dict iteration.
marimo/_runtime/reload/autoreload.py Iterate dict directly instead of .keys().
marimo/_runtime/primitives.py Prefer set literal and generator any(...) forms.
marimo/_runtime/patches.py Avoid list allocation inside min(...).
marimo/_runtime/packages/utils.py Use tuple-form .endswith((...)) in parser.
marimo/_runtime/packages/pypi_package_manager.py Use tuple-form .startswith((...)); simplify boolean returns and suffix checks.
marimo/_runtime/packages/module_registry.py Prefer set comprehension literals; simplify expression in missing_modules.
marimo/_runtime/functions.py Replace raise e with bare raise to preserve traceback.
marimo/_runtime/dataflow/runner.py Prefer set comprehension literal over set([...]).
marimo/_runtime/dataflow/init.py Prefer set comprehensions for induced subgraphs and edges.
marimo/_runtime/copy.py Prefer set literal for slot filtering; use Self return annotation.
marimo/_runtime/complete.py Simplify boolean flow; minor idiom cleanups; simplify set subtraction expression.
marimo/_runtime/commands.py Prefer request.get(...) over membership checks.
marimo/_runtime/app/script_runner.py Prefer set comprehension; replace raise e with bare raise.
marimo/_plugins/ui/_impl/utils/dataframe.py Reorder docstring sections to match conventions.
marimo/_plugins/ui/_impl/tabs.py Prefer list comprehension over list(generator).
marimo/_plugins/ui/_impl/tables/pandas_table.py Use tuple-form .startswith((...)) for dtype checks.
marimo/_plugins/ui/_impl/tables/narwhals_table.py Iterate dict directly instead of .keys().
marimo/_plugins/ui/_impl/tables/default_table.py Iterate dict directly instead of .keys().
marimo/_plugins/ui/_impl/table.py Use tuple-form isinstance(..., (...)); simplify list comprehension filtering.
marimo/_plugins/ui/_impl/run_button.py Add noqa for Ruff SIM103 expectation on sentinel check.
marimo/_plugins/ui/_impl/plotly.py Simplify boolean return logic.
marimo/_plugins/ui/_impl/file_browser.py Avoid unnecessary list(...) around iterator.
marimo/_plugins/ui/_impl/data_explorer.py Prefer dict literal over dict(...) for spec construction.
marimo/_plugins/ui/_impl/data_editor.py Iterate dict directly instead of .keys() for row operations.
marimo/_plugins/stateless/nav_menu.py Use tuple-form .startswith((...)) for href validation.
marimo/_plugins/stateless/image.py Use tuple-form isinstance(..., (...)) for IO types.
marimo/_plugins/stateless/image_compare.py Use tuple-form isinstance(..., (...)) for IO types.
marimo/_plugins/stateless/accordion.py Prefer list comprehension over list(generator).
marimo/_output/formatters/structures.py Prefer () literal over tuple() for formatter identity check.
marimo/_messaging/msgspec_encoder.py Avoid unnecessary list allocations in list conversions.
marimo/_messaging/console_output_worker.py Prefer .get over membership+index in dict access.
marimo/_lint/validate_graph.py Avoid unnecessary list(set(...)) allocation before sorting; prefer set literal operations.
marimo/_lint/rules/runtime/branch_expression.py Simplify boolean branches to direct comparisons.
marimo/_lint/rules/formatting/markdown_dedent.py Avoid list allocation inside any(...); use generator form.
marimo/_lint/rule_engine.py Simplify boolean return; rename unused pending set to _pending.
marimo/_dependencies/dependencies.py Minor lint-driven cleanup in dependency declarations.
marimo/_data/get_datasets.py Use tuple-form .startswith((...)) and simplify nested-type checks.
marimo/_convert/markdown/to_ir.py Simplify string construction for formatted blocks.
marimo/_convert/ipynb/to_ir.py Use tuple-form .startswith((...)); simplify boolean returns.
marimo/_convert/ipynb/init.py Reorder __all__ entries without functional change.
marimo/_convert/common/init.py Reorder __all__ entries without functional change.
marimo/_code_mode/_context.py Use Self for async context manager enter return type.
marimo/_cli/files/file_path.py Simplify boolean returns; reorder docstring sections.
marimo/_ast/visitor.py Prefer set comprehension literal over set([...]).
marimo/_ast/toplevel.py Prefer set comprehension literal over set([...]).
marimo/_ast/scanner.py Use tuple-form .startswith((...)) for return stripping checks.
marimo/_ast/codegen.py Prefer () literal for empty tuples; simplify string joins and boolean returns.
marimo/_ast/cell.py Prefer set comprehension literal; simplify comparisons and next(iter(...)) usage.
marimo/_ast/cell_manager.py Iterate dict directly instead of .keys().
marimo/_ast/app.py Rename unused _linter binding from helper call.
marimo/_ai/_tools/base.py Fix ABC/Generic base ordering for typing correctness.
marimo/init.py Reorder __all__ exports (no functional change expected).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 132 out of 132 changed files in this pull request and generated no new comments.

@Light2Dark Light2Dark marked this pull request as ready for review April 10, 2026 18:20
@Light2Dark Light2Dark requested review from kirangadhave and removed request for akshayka April 10, 2026 18:20
pytest = Dependency("pytest")
vegafusion = Dependency("vegafusion")
vl_convert_python = Dependency("vl_convert")
dotenv = Dependency("dotenv")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need this no?

pandas = Dependency("pandas")
polars = Dependency("polars")
ibis = Dependency("ibis")
dotenv = Dependency("dotenv")

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's a duplicate @mscolnick . Cool that ruff picked it up

@mscolnick

Copy link
Copy Markdown
Contributor

merging now to avoid conflicts

@mscolnick mscolnick merged commit 0c319d2 into main Apr 10, 2026
52 of 54 checks passed
@mscolnick mscolnick deleted the sham/additional-ruff-fixes branch April 10, 2026 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal A refactor or improvement that is not user facing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants