-
Notifications
You must be signed in to change notification settings - Fork 879
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
FA102 should ignore quoted annotations #11397
Comments
This sounds right to me. |
I'm not sure, this feels like intentional behaviour to me (#11414 (comment)) -- one of the motivating reasons for FA102 is to enable UP037 to automatically remove quotes from your annotations for you. You say you find the |
@inoa-jboliveira, what's your reason for enabling FA102 in the first place if you find the |
Hi @AlexWaygood , thank you for the reply. I have some considerations
Of course the purpose is to check if the code is compatible older verions, it says so in the docs:
I want the check, I just don't want the proposed fix. For us is quite important if the code is invalid, but there are multiple ways to solve this problem. I don't like UP037 because it is an opinonated fix that is meant for when a class references itself before it is fully created. There is a lot more depth around the annotation issues and "from future import annotations" have been postponed multiple times because people cannot agree yet on it. I think it might some day become the right approach, but until so I might not want to use it. From python docs:
|
yeah, sorry, I got quite mixed up here 🙃 -- #11414 (comment). I'll go ahead and blame it on some significant jetlag :( |
… type annotations (#11414) ## Summary If an annotation won't be evaluated at runtime, we don't need to flag `from __future__ import annotations` as required. This applies both to quoted annotations and annotations outside of runtime-evaluated positions, like: ```python def main() -> None: a_list: list[str] | None = [] a_list.append("hello") ``` Closes #11397.
ruff 0.4.4 (3e8878a 2024-05-09)
We have an application that targets Python 3.9+, but instead of
from __future__ import annotations
on all files that is kinda ugly and unnecessary most of the time, whenever people need PEP 604 syntax they put the annotation within quotes which is effectively the same as the future import does except when someones accesses said annotations in run time (we don't).See excerpt below:
I believe FA102 should just ignore the annotation if it is within quotes. It should not mark this as violation because the code is indeed compatible with Python 3.9.
The text was updated successfully, but these errors were encountered: