-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
F821 (Undefined name) and F722 (bad forward annotation) can trigger on @no_type_check
-ed annotations
#13824
Comments
Thanks for reporting. Suppressing some rules annotated with |
This seems reasonable to me too |
Should we just skip visiting them altogether when in a |
That might make sense, yeah |
Are you suggesting skipping such functions only for |
I'm suggesting skipping looking at those nodes entirely, for all rules. |
Alternatively, we could visit them as strings (so enforce rules like implicit concat -- weird but possible) but skip parsing them and visiting the content. |
To clarify, with all nodes you mean skipping the entire function or only the type annotations? I'm somewhat fine skipping the annotations but would find it a stretch if we skip the entire function |
Just the annotations. The rest of the function would be unchanged. |
This reverts commit 9aa4913.
This seems to have been resolved by #14615. |
We'll probably revert this change. It's a bit more involved, see #14698 |
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:
Save it as "demo.py" and run ruff with:
This will emit the following errors, which are all false-positives:
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:
ruff --version: 0.7.0
settings: no config file exists
The text was updated successfully, but these errors were encountered: