Skip to content

marimo incorrectly concludes a class def can't be reused when a class var is reused in class scope #7265

@wkschwartz

Description

@wkschwartz

Describe the bug

Marimo says a cell containing the following is a reusable class definition.

class K:
    A: int = 1
    def b(a: int = 1) -> int:
        return a

However, marimo says that a cell containing the following is not a reusable class definition.

class K:
    A: int = 1
    def b(a: int = A) -> int:
        return a

The hover text in the circled question mark in the bottom right corner of the cell says, "This function depends on variables defined by other cells: {'A'}...". The difference between the two snippets is the use in the latter of A in class scope. Here's another example that is also not reusable according to marimo:

class K:
    A: int = 1
    B: int = A
    def b(a: int = 1) -> int:
        return a

The correct behavior would be to notice that A was defined in class scope and does not come from another cell (and does not leak out of this cell except through class K).

Will you submit a PR?

No

Environment

Details
{
  "marimo": "0.18.0",
  "editable": false,
  "location": "$LOCALAPPDATA/uv/cache/archive-v0/vVa0LoFIQedWJEgGGbZoX/Lib/site-packages/marimo",
  "OS": "Windows",
  "OS Version": "11",
  "Processor": "Intel64 Family 6 Model 186 Stepping 3, GenuineIntel",
  "Python Version": "3.13.7",
  "Locale": "en_US",
  "Binaries": {
    "Browser": "133.0.6943.99",
    "Node": "--"
  },
  "Dependencies": {
    "click": "8.3.1",
    "docutils": "0.22.3",
    "itsdangerous": "2.2.0",
    "jedi": "0.19.2",
    "markdown": "3.10",
    "narwhals": "2.12.0",
    "packaging": "25.0",
    "psutil": "7.1.3",
    "pygments": "2.19.2",
    "pymdown-extensions": "10.17.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": {
    "loro": "1.8.2",
    "python-lsp-ruff": "2.3.0",
    "python-lsp-server": "1.13.2",
    "ruff": "0.14.6"
  },
  "Experimental Flags": {}
}

Code to reproduce

See description above.

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