Skip to content

"_cell_YXGs_a is not defined" when using a underscore prefixed local in a function #9623

@rambip

Description

@rambip

Describe the bug

If I define a local with an underscore (like _a) and use it in another cell, I get a nice error message.
But if try to I use it in a function in another cell, I get an error that is quite confusing for newcomers.

Image

Maybe related to #4064

Will you submit a PR?

  • Yes

Environment

\`\`\`

{
"marimo": "0.23.5",
"editable": false,
"location": "/usr/local/lib/python3.13/site-packages/marimo",
"OS": "Linux",
"OS Version": "4.4.0",
"Processor": "",
"Python Version": "3.13.11",
"Locale": "en_US",
"Binaries": {
"Browser": "--",
"Node": "v22.22.2",
"uv": "0.11.11 (x86_64-unknown-linux-gnu)"
},
"Dependencies": {
"click": "8.3.3",
"docutils": "0.22.4",
"itsdangerous": "2.2.0",
"jedi": "0.19.2",
"markdown": "3.10.2",
"narwhals": "2.20.0",
"packaging": "26.2",
"psutil": "7.2.2",
"pygments": "2.20.0",
"pymdown-extensions": "10.21.2",
"pyyaml": "6.0.3",
"starlette": "1.0.0",
"tomlkit": "0.14.0",
"typing-extensions": "4.15.0",
"uvicorn": "0.46.0",
"websockets": "16.0"
},
"Optional Dependencies": {
"altair": "6.1.0",
"anywidget": "0.11.0",
"duckdb": "1.5.2",
"loro": "1.10.3",
"nbformat": "5.10.4",
"openai": "2.35.1",
"pandas": "3.0.2",
"polars": "1.40.1",
"pyarrow": "24.0.0",
"pytest": "9.0.3",
"python-lsp-ruff": "2.3.1",
"python-lsp-server": "1.14.0",
"ruff": "0.15.12",
"sqlglot": "30.7.0",
"ty": "0.0.34"
},
"Experimental Flags": {}
}

Code to reproduce

# /// script
# requires-python = ">=3.13"
# dependencies = [
#     "marimo>=0.23.6",
# ]
# ///

import marimo

__generated_with = "0.23.5"
app = marimo.App(
    width="medium",
    css_file="/usr/local/_marimo/custom.css",
    auto_download=["html"],
)


@app.cell
def _():
    _a = 1
    return


@app.function
def test():
    print(_a)


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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions