-
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
[ruff-0.8] [FAST
] Further improve docs for fast-api-non-annotated-depencency
(FAST002
)
#14467
Conversation
72aee00
to
e8ce962
Compare
|
Thinking about this some more, I think we should at least mark the autofix as unsafe if the target version is set to Python 3.8 or lower, since the autofix adds imports of typing_extensions on these older Python versions, which the user might not have or want as a dependency. So the fix could easily break working Python code on older Python versions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's say we hold back on stabilizing this rule now because of Python 3.8. How would you change the rule or what are the next steps to stabilize this rule in an upcoming release?
To me it's unclear what that change would be:
- We could only flag the rule for Python 3.9 or newer, but this makes the rule useless for users targeting Python 3.8 that want the rule
- We could introduce an option, but an option is equivalent to toggling the rule
- We could test if a typing module is already imported. I don't think this will be very useful unless it's done globally and not on a per file level, which Ruff doesn't support.
That's why think we should stabilize the rule. Users that don't want typing rules can disable the rule.
And nice find! |
4f95abf
to
b61eda2
Compare
e8ce962
to
b66d9b6
Compare
…depencency` (`FAST002`)
b66d9b6
to
b4015b0
Compare
Okay, this isn't an issue, because the fix is already marked as unsafe on all Python versions. However, there's no |
Landing for now; this is an improvement on the status quo, and we can always add more docs on the safety of the fix as a followup |
I opened #14484 |
…depencency` (`FAST002`) (#14467)
This PR is stacked on top of #14466.
Summary
This PR updates the docs for
FAST002
to note thattyping.Annotated
was added in Python 3.9, but thattyping_extensions.Annotated
can be used on older versions of Python.Alternatively, we could consider reverting the stabilisation of this rule, since not everybody will necessarily be happy to add
typing_extensions
as a dependency, but the autofix assumes that it is available to be imported on Python 3.8 and lower. However, nobody has raised this issue, and Python 3.8 is now end-of-life, so while this isn't ideal I think it probably shouldn't block the rule being stabilised. If you are on an older version of Python and don't wanttyping_extensions
as a dependency, you can always just disable the rule.I don't have a strong opinion here, though; this does feel sort-of borderline to me. Maybe we should revert the stabilisation?
Test Plan
cargo test -p ruff_linter