Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
[
FastAPI
] UpdateAnnotated
fixes (FAST002
) #15462[
FastAPI
] UpdateAnnotated
fixes (FAST002
) #15462Changes from 13 commits
3dab449
631f75f
f65ecdb
c030481
5ed7cd6
c65c3dc
86b06a9
4e2d304
aa175fe
48eaf55
40df4e8
bf9486f
7ac4513
34c241a
14fb045
9ec503b
e31746e
7ef87ea
3335c03
6f7a8ad
c931f85
ed4a086
7b723cf
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
We'll fail to update
seen_default
if adding the import fails. That's probably fine because it's unlikely that importing the symbol will succeed for the next parameter but it might proof a footgun in the future if we happen to add other code paths that bail early.Should we move the
parameter_edit
generation out of thetry_set_optional_fix
to ensure it always runs to completion? (unless we manage to find a way to moveseen_default
out ofcreate_diagnostic
which would be my preferred solution)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.
Wow good catch. Did you have something in mind here? I tried naively moving most of the
try_set_optional_fix
body out, but we need thebinding
from the import to generatecontent
.My fix now is to call the closure and check its
Result
before sending it totry_set_optional_fix
, but that feels a bit awkward too.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.
I find the name
is_dep
slightly confusing because it explicitly excludesDepends
. How about:is_route_param
is_route
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.
What's the reason for only setting
is_default
totrue
ifis_dep
is true? What if a nonis_dep
argument has a default value?If it's possible to set
seen_default
totrue
whenever there's a default value, I then suggest movingseen_default
out of this function and simplify it to always compute it on line 115 (on the call site)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.
Computing it at the call site is how the original code was, but I think now we need more information (both
is_dep && default_arg.is_some()
) to know if the current fix will lead to a default argument. The examples I'm trying to handle here are cases likesome_path_param: str = Path()
becomingsome_path_param: Annotated[str, Path()]
, where the initial presence of a default argument, which is checkable at the call site, doesn't determine the final presence of a default.is_dep
might be a bad name for this, at a minimum.Totally non-
is_dep
arguments (failing theis_fastapi_dependency
check) are handled in the caller at 118.Does that make sense? I felt like I was over-complicating this yesterday, so the answer could definitely be "no," but it still looks right to me today.