Description
When running mypy on marimo notebooks, mypy reports error: Name "__" already defined on line X [no-redef] errors because cells in marimo notebooks are all defined as functions with the same name: __. This makes it difficult to properly type-check marimo notebooks.
Suggested solution
There are at least three approaches to resolve this:
- Define cells as functions with unique names. This approach eradicates the root cause, but possibly has side effects causing other issues.
- Add
# type: ignore[no-redef] comments to lines containing @app.cell to suppress errors. This approach has probably the fewest side effects but makes the files a bit noisy.
- Add a top-level
#mypy: disable-error-code="no-redef" comment. This approach is probably the least noisy but possibly suppresses other no-redef errors in the file.
Alternative
No response
Additional context
As far as I know, there is no way to configure mypy to ignore a certain error in specific files (like per-file-ignores config in Ruff) via configuration files such as pyproject.toml. So it's impossible to suppress the no-redef errors in marimo notebooks without modifying the notebook files.
So my current workaround is to take approach 3 and manually adding the top-level #mypy: disable-error-code="no-redef" comment to every marimo notebook.
Description
When running
mypyon marimo notebooks,mypyreportserror: Name "__" already defined on line X [no-redef]errors because cells in marimo notebooks are all defined as functions with the same name:__. This makes it difficult to properly type-check marimo notebooks.Suggested solution
There are at least three approaches to resolve this:
# type: ignore[no-redef]comments to lines containing@app.cellto suppress errors. This approach has probably the fewest side effects but makes the files a bit noisy.#mypy: disable-error-code="no-redef"comment. This approach is probably the least noisy but possibly suppresses otherno-redeferrors in the file.Alternative
No response
Additional context
As far as I know, there is no way to configure
mypyto ignore a certain error in specific files (likeper-file-ignoresconfig in Ruff) via configuration files such aspyproject.toml. So it's impossible to suppress theno-redeferrors in marimo notebooks without modifying the notebook files.So my current workaround is to take approach 3 and manually adding the top-level
#mypy: disable-error-code="no-redef"comment to every marimo notebook.