astral-sh / ruff-vscode

A Visual Studio Code extension with support for the Ruff linter.
Other
1.06k stars 53 forks source link

Variable named "time" incorrectly marked as "Undefined name" (F821) in Jupyter notebook #376

Closed wizardrix closed 9 months ago

wizardrix commented 9 months ago

In Jupyter notebook I'm getting the hint "Undefined name time - Ruff(F821)" when I'm specifically using a variable with the name "time" and reference it in another cell.

Minimal example to reproduce:

First cell

time = "hi"

(this is not marked)

Second cell

test = time + " hello"

(here "time" is marked)

relevant settings:

{
    "[python]": {
        "editor.defaultFormatter": "charliermarsh.ruff"
    },
    "python.analysis.typeCheckingMode": "basic",
    "python.analysis.diagnosticSeverityOverrides": {
        "reportPrivateUsage": "error"
    },
    "notebook.formatOnSave.enabled": true,
    "notebook.showCellStatusBar": "hidden",
    "notebook.insertFinalNewline": false,
    "editor.largeFileOptimizations": false
}

VS Code 1.85.1 Ruff v2023.60.0

charliermarsh commented 9 months ago

I believe this is the same as https://github.com/astral-sh/ruff/issues/8526 -- we have trouble distinguishing variables from magic commands of the same name. Merging into that issue...