Skip to content

Marimo ast parser got confused parsing something like: Final[Literal['int8']] resulting in SyntaxError #7026

@kelreeeeey

Description

@kelreeeeey

Describe the bug

I got this when annotating variables within marimo

File "...\...\bug_marimo_ast_parser.py", line 30
    DTYPE_FAULT: "Final[Literal["int8"]]",
                 ^^^^^^^^^^^^^^^^^^^^
SyntaxError: invalid syntax. Perhaps you forgot a comma?

How did i get into this

  • I was using edit mode on a directory to create notebooks, one of them contains annotation shown above
  • All is good, until i close the notebook and reopen it.
  • However, manual editing on the notebook script removes the bug

Will you submit a PR?

  • Yes

Environment

marimo v0.17.5

Code to reproduce

Initial code:

import marimo

__generated_with = "0.17.5"
app = marimo.App(width="columns", sql_output="polars")


@app.cell
def _():
    import marimo as mo
    return


@app.cell(hide_code=True)
def _():
    from   typing  import Final, Literal
    return Final, Literal


@app.cell
def _(Final, Literal):
    CHUNKS_SIZE: Final[tuple[int, int, int]] = (128, 128, 128)
    DTYPE_FAULT: Final[Literal['int8']] = "int8"
    DTYPE_SEIS : Final[Literal['float16']] = "float16"
    return CHUNKS_SIZE, DTYPE_FAULT, DTYPE_SEIS


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

Then I edit above notebook so it'd be like

import marimo

__generated_with = "0.17.5"
app = marimo.App(width="columns", sql_output="polars")


@app.cell
def _():
    import marimo as mo
    return


@app.cell(hide_code=True)
def _():
    from   typing  import Final, Literal
    return Final, Literal


@app.cell
def _(Final, Literal):
    CHUNKS_SIZE: Final[tuple[int, int, int]] = (128, 128, 128)
    DTYPE_FAULT: Final[Literal['int8']] = "int8"
    DTYPE_SEIS : Final[Literal['float16']] = "float16"
    return CHUNKS_SIZE, DTYPE_FAULT, DTYPE_SEIS


@app.cell
def _(
    CHUNKS_SIZE: "Final[tuple[int, int, int]]",
    DTYPE_FAULT: "Final[Literal["int8"]]",
    DTYPE_SEIS: "Final[Literal["float16"]]",
):
    print(CHUNKS_SIZE, DTYPE_FAULT, DTYPE_SEIS)
    return


@app.cell
def _():
    return


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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions