-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
FA100 issue: Ruff doesnt suggest adding from __future__ import annotations
#13273
Comments
from __future__ import annotations
from __future__ import annotations
I think there are multiple things at play here.
|
If you know you want |
I dont think, thats true: 2024-09-07.14-28-56.mp4As you can see, error appears after adding
Im not talking about autofixing this rule (ruff have autofix option). Im talking, that i want ruff to tell me every time when some import is used only for type hint |
I dont rly want |
You're right. The problem was that the original code snipped contained a syntax error. It works as expected if I fix the syntax error playground |
The same file with flake8 and flake8-type-checking emits the necessary error codes:
flake8-type-checking doesn't care whether you have imported future annotations yet. If you fix the imports by moving them into T.TYPE_CHECKING, it will still emit an error telling you how to fix your use of annotations that are evaluated at runtime and aren't available, via the "how to handle forward references" (there's an option to have it always advise you to use quoted strings instead):
It might be nice for flake8-type-checking to warn you about both at the same time. I just recently opened snok/flake8-type-checking#190 which is related to this but not exactly the same thing. In the same situation, by the way, ruff reports:
It's not used for more than type hinting, but whatever. ;) |
By the way my reading of FA100 is that it is specifically applicable to cases where an annotation could be rewritten in a manner that ordinarily requires a new version of CPython, but where It is not about unlocking additional ways to discover TCH001-TCH003 "move import into a type-checking block" issues. |
So, can we treat this issue as feature request or should i create another one? |
BTW, ruff has a feature that automatically moves imports under the TYPE_CHECKING block, but this can cause issues with tools like |
Search keywords
"TCH rules", "move under TYPE_CHECKING", "FA100"
Ruff Version
0.5.7
Config
Part of pyproject.toml
Bug Report
My request:
I would like all imports that are used only for type hints to be placed under a TYPE_CHECKING block. If you have not yet implemented this function, please consider this issue as a feature request.
Sometimes ruff doesn't detect imports, that are used only for type-hints without
from __future__ import anotations
. I know, that existing offrom __future__ import anotations
is one of requirements for ruff to make giveTCH
-warnings. But sometimesFA100
rules doesnt detect cases, when import is used only for type-hints. I will make an example for django-migration:No ruff-warnings are shown in this code.
The text was updated successfully, but these errors were encountered: