Skip to content
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

Add suggestion or fix for FA102 (future-required-type-annotation) #8682

Closed
RunDevelopment opened this issue Nov 14, 2023 · 3 comments · Fixed by #8711
Closed

Add suggestion or fix for FA102 (future-required-type-annotation) #8682

RunDevelopment opened this issue Nov 14, 2023 · 3 comments · Fixed by #8711
Assignees
Labels
fixes Related to suggested fixes for violations

Comments

@RunDevelopment
Copy link

The rule FA102 (future-required-type-annotation) is very useful when writing code in a code base that support python <3.10. The only issue with this rule is that it only tells you that a from __future__ import annotations is required, it doesn't have any way of applying the suggested fix.

Please add a suggestion or fix for this rule to automatically add the missing from __future__ import annotations.

Code example:

# py 3.8 code base
def foo(l: list[int]): ...
@charliermarsh
Copy link
Member

charliermarsh commented Nov 14, 2023

One way to achieve this is via missing-required-import (I002) -- you can mark from __future__ import annotations, and it'll be added to all non-empty files (see: https://docs.astral.sh/ruff/settings/#isort-required-imports):

[tool.ruff.lint.isort]
required-imports = ["from __future__ import annotations"]

@charliermarsh charliermarsh added the fixes Related to suggested fixes for violations label Nov 14, 2023
@charliermarsh charliermarsh self-assigned this Nov 16, 2023
@charliermarsh
Copy link
Member

I will fix this :)

charliermarsh added a commit that referenced this issue Nov 16, 2023
## Summary

We already support inserting imports for `I002` -- this PR just adds the
same fix for `FA102`, which is explicitly about `from __future__ import
annotations`.

Closes #8682.
@RunDevelopment
Copy link
Author

RunDevelopment commented Nov 16, 2023

Thank you @charliermarsh!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixes Related to suggested fixes for violations
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants