-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Labels
help wantedContributions especially welcomeContributions especially welcomeruleImplementing or modifying a lint ruleImplementing or modifying a lint rule
Description
Hi! I found that F821 ("Undefined name") and F722 ("Syntax error in forward annotation") can erroneously trigger on functions that marked @no_type_check, if they happen to either use names that aren't in scope, or aren't even valid Python.
Consider the following example file:
from typing import no_type_check
@no_type_check
def f821(arg: "A") -> "R":
pass
@no_type_check
def f722(arg: "this isn't python") -> "this isn't python either":
passSave it as "demo.py" and run ruff with:
ruff check --isolated --select=F722,F821 demo.py --output-format concise
This will emit the following errors, which are all false-positives:
demo.py:4:16: F821 Undefined name `A`
demo.py:4:24: F821 Undefined name `R`
demo.py:8:15: F722 Syntax error in forward annotation: `this isn't python`
demo.py:8:39: F722 Syntax error in forward annotation: `this isn't python either`
Found 4 errors.
I'm presuming (but haven't tested) that this could apply to other rules that inspect annotations as well. Ruff should treat these annotations as opaque strings without any meaning. As per PEP-484:
Functions with the
@no_type_checkdecorator should be treated as having no annotations.
ruff --version: 0.7.0
settings: no config file exists
Metadata
Metadata
Assignees
Labels
help wantedContributions especially welcomeContributions especially welcomeruleImplementing or modifying a lint ruleImplementing or modifying a lint rule