Skip to content

feat: persist pragma comments in marimo check --fix #7530

@martimlobao

Description

@martimlobao

Describe the bug

I'm running marimo check and marimo check --fix to lint and fix issues in my notebooks, and noticed that marimo is removing commented out lines that it does not complain about when running check and that are not problematic to running the notebook.

❯ uv run marimo check notebooks/example.py

❯ uv run marimo check --fix notebooks/example.py
Updated: notebooks/example.py
Updated 1 file.

This is particularly annoying since the comments I'm adding are necessary to disable test coverage calculation (using # pragma: no cover), since I don't want untestable cell definitions to decrease my test coverage. (As an aside, am I right in that there's no way to create unit tests for cell definitions?)

Will you submit a PR?

  • Yes

Environment

Details
❯ uv run marimo env                                       
{
  "marimo": "0.18.4",
  "editable": false,
  "location": "https://github.com/Users/martim/Documents/example/.venv/lib/python3.13/site-packages/marimo",
  "OS": "Darwin",
  "OS Version": "25.1.0",
  "Processor": "arm",
  "Python Version": "3.13.0",
  "Locale": "en_US",
  "Binaries": {
    "Browser": "--",
    "Node": "v25.2.1"
  },
  "Dependencies": {
    "click": "8.3.1",
    "docutils": "0.22.3",
    "itsdangerous": "2.2.0",
    "jedi": "0.19.2",
    "markdown": "3.10",
    "narwhals": "2.14.0",
    "packaging": "25.0",
    "psutil": "7.1.3",
    "pygments": "2.19.2",
    "pymdown-extensions": "10.19.1",
    "pyyaml": "6.0.3",
    "starlette": "0.50.0",
    "tomlkit": "0.13.3",
    "typing-extensions": "4.15.0",
    "uvicorn": "0.38.0",
    "websockets": "15.0.1"
  },
  "Optional Dependencies": {
    "altair": "6.0.0",
    "duckdb": "1.4.3",
    "loro": "1.10.3",
    "mcp": "1.24.0",
    "nbformat": "5.10.4",
    "openai": "2.13.0",
    "pandas": "2.3.3",
    "polars": "1.36.1",
    "pyarrow": "22.0.0",
    "pytest": "9.0.2",
    "ruff": "0.14.9",
    "sqlglot": "28.4.1",
    "ty": "0.0.2"
  },
  "Experimental Flags": {}
}

Code to reproduce

import marimo

__generated_with = "0.18.4"
app = marimo.App(width="medium")


@app.cell  # pragma: no cover
def _():
    print("hello world")
    return


if __name__ == "__main__":
    app.run()

Then run uv run marimo check notebooks/example.py and uv run marimo check --fix notebooks/example.py

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions