Skip to content

ty does not respect cell-local private variable scope #591

Description

@Antyos

Describe the bug

I can't think of a better name for this.

There are two cases I've noticed:

  1. Variables in cells placed before they are defined will have red squiggles under them until the cell where they are defined is run. However, I would expect that Marimo would know about the variable and not require running the cell for the error to go away.
  2. Undefined private variables will not show an undefined name error if they are declared in a different cell (which is not how Marimo works).

See, for example:

Image

Environment

Details
marimo VS Code Extension Diagnostics
=====================================

Language Server (LSP):
	UV Bin: Bundled (c:\Users\avg170002\.vscode\extensions\marimo-team.vscode-marimo-0.13.3-win32-x64\bundled\libs\bin\uv.exe)
	UV: 0.11.3 (45da18ac3 2026-04-01) ✓
	Using bundled marimo-lsp via uvx

Python Extension:
	Interpreter: c:\Users\avg170002\Code\project\code\.venv\Scripts\python.exe
	Version: 3.13.9.final.0
	Environment: VirtualEnvironment (biaxtic)

Python Language Server (ty):
	Status: running ✓
	Version: 0.0.26 (940305127 2026-03-26)
	Binary: UvInstalled (c:\Users\avg170002\AppData\Roaming\Code\User\globalStorage\marimo-team.vscode-marimo\libs\bin\ty.exe)
	Python: c:\Users\avg170002\Code\project\code\.venv\Scripts\python.exe (3.13.9.final.0)

Ruff Language Server:
	Status: running ✓
	Version: 0.15.16
	Binary: CompanionExtension/bundled (charliermarsh.ruff, c:\Users\avg170002\.vscode\extensions\charliermarsh.ruff-2026.48.0-win32-x64\bundled\libs\bin\ruff.exe)

Extension Configuration:
	Version: 0.13.3 
	UV integration disabled: false 

System Information:
	Host: desktop 
	IDE: Visual Studio Code 
	IDE version: 1.124.0 
	Platform: win32 
	Architecture: x64 
	Node version: v24.15.0 

Common Issues:
	1. If notebooks won't open:
		- Check Python interpreter is selected
		- Ensure marimo is installed
		- Check 'marimo-lsp' output channel for errors
	2. If features are missing:
		 - Ensure marimo version is >= 0.23.3
		- Try reloading the window

Steps to reproduce

Example notebook

import marimo

__generated_with = "0.23.6"
app = marimo.App()

with app.setup:
    import marimo as mo


@app.cell
def _(x):
    print(x)  # <- Has red squiggles until next cell is run
    #         # ty(unresolved-reference): Name `x` used when not defined
    #         # ruff(F821): undefined name 'x'
    return


@app.cell
def _():
    _x = 3
    x = 3
    return (x,)


@app.cell
def _():
    print(_x)  # <- Should have red squiggles
    print(_y)  # <- Has red squiggles
    return


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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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