ruff icon indicating copy to clipboard operation
ruff copied to clipboard

FA102 should ignore quoted annotations

Open inoa-jboliveira opened this issue 9 months ago • 5 comments

ruff 0.4.4 (3e8878a1c 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:

setup\split_code_files.py:96:34: FA102 Missing `from __future__ import annotations`, but uses PEP 604 union
   |
94 |         self.nodes = self.get_ast_nodes()
95 |
96 |     def get_yaml_nodes(self) -> 'dict[str, str] | None':
   |                                  ^^^^^^^^^^^^^^^^^^^^^ FA102
97 |         try:
98 |             with open(self.yaml_file) as yaml_file:
   |
   = help: Add `from __future__ import annotations`

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.

inoa-jboliveira avatar May 13 '24 04:05 inoa-jboliveira