marimo
marimo copied to clipboard
Formatter line length fighting between cells and functions
Describe the bug
When formatting code in Marimo cells, lines near the wrap limit (default 88) will be formatted differently inside and outside of Marimo. This does not occur with function or class cells.
I suspect this is because Marimo is hides the leading space in the cell definition that exists in the raw Python file, i.e., the 88th character of a Marimo cell (but not a function or class definition), is actually the 92nd character of the .py file because of the indent of cell function. I can see the logic behind this choice, but since it can cause fighting between formatters in specific cases, I thought I might as well document the issue.
Example
With default setting of line_length = 88
Formatted by Marimo:
@app.cell
def _():
print("This ')' on this line is at character 92 ")
return
@app.function
def foo():
print("This ')' on this line is at character 88 ")
Formatted by Ruff:
@app.cell
def _():
print(
"This ')' on this line is at character 92 "
)
# (Or, at least it was...)
return
@app.function
def foo():
print("This ')' on this line is at character 88 ")
Will you submit a PR?
- [ ] Yes
Environment
{
"marimo": "0.17.0",
"editable": false,
"location": "C:/Users/andrew/Code/project/code/.venv/Lib/site-packages/marimo",
"OS": "Windows",
"OS Version": "11",
"Processor": "Intel64 Family 6 Model 198 Stepping 2, GenuineIntel",
"Python Version": "3.13.6",
"Locale": "en_US",
"Binaries": {
"Browser": "--",
"Node": "v22.20.0"
},
"Dependencies": {
"click": "8.2.1",
"docutils": "0.22",
"itsdangerous": "2.2.0",
"jedi": "0.19.2",
"markdown": "3.8.2",
"narwhals": "2.2.0",
"packaging": "25.0",
"psutil": "7.0.0",
"pygments": "2.19.2",
"pymdown-extensions": "10.16.1",
"pyyaml": "6.0.2",
"starlette": "0.47.3",
"tomlkit": "0.13.3",
"typing-extensions": "4.15.0",
"uvicorn": "0.35.0",
"websockets": "15.0.1"
},
"Optional Dependencies": {
"altair": "5.5.0",
"duckdb": "1.3.2",
"nbformat": "5.10.4",
"openai": "1.102.0",
"pandas": "2.3.2",
"polars": "1.32.3",
"pyarrow": "21.0.0",
"loro": "1.5.4",
"pytest": "8.4.1",
"python-lsp-ruff": "2.2.2",
"python-lsp-server": "1.13.1",
"ruff": "0.12.11",
"sqlglot": "27.9.0"
},
"Experimental Flags": {}
}
Code to reproduce
import marimo
__generated_with = "0.17.0"
app = marimo.App(width="medium")
@app.cell
def _():
print(
"This ')' on this line is at character 92 "
)
return
@app.function
def foo():
print("This ')' on this line is at character 88 ")
if __name__ == "__main__":
app.run()
Thanks, this is known. You're correct that the line length in marimo is with respect to the cell editor (not including the leading whitespace). I'm not sure we want to change that, it might be confusing?
Are you raising this because you run ruff format on your marimo notebooks, leading to noisy diffs? I can see how that would be bothersome
I do editing in VS Code (where I have format on save) as well as Marimo, so that's where the noisy diffs come in. I tried setting the line length in Marimo to 84, which worked for cells, but then function and class definitions suffered instead.
Perhaps you could add an option to reduce the line length in cells by the indent level, or would that be too confusing to novices?