astral-sh / ruff-vscode

A Visual Studio Code extension with support for the Ruff linter.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

wizardrix opened this issue · comments

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

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