fix: do not suggest FromQuery for path parameter defaults - #5019
Open
Sharawey74 wants to merge 1 commit into
Open
fix: do not suggest FromQuery for path parameter defaults#5019Sharawey74 wants to merge 1 commit into
Sharawey74 wants to merge 1 commit into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5019 +/- ##
==========================================
- Coverage 67.19% 67.19% -0.01%
==========================================
Files 293 293
Lines 15363 15365 +2
Branches 1745 1745
==========================================
+ Hits 10323 10324 +1
- Misses 4890 4891 +1
Partials 150 150 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Author
|
The two failing checks here are unrelated to this change:
All six required checks pass, and the test matrix is green on 3.11 through 3.14. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #5018
Description
raise_for_kwarg_as_defaultmapsParameterKwarg.param_typeto the replacement syntax it recommends. For a plainParameter()that mapping is unreliable:param_typedefaults toParamType.QUERYand only changes whenheader=,cookie=orquery=is passed, so a path parameter is told to useFromQuery.This adds a check for whether
param_typewas actually chosen, and only uses the alias mapping when it was. Otherwise the message falls back toAnnotated[<type>, Parameter(...)], which is valid for every parameter kind.param_typecounts as chosen when either the default is one of the dedicated subclasses (QueryParameter,PathParameter,HeaderParameter,CookieParameter), which set it themselves, or one ofheader=/cookie=/query=was passed.The route path is not usable at this point.
FieldDefinition.from_annotationinspects one parameter in isolation, andraise_for_kwarg_as_defaultis also called from DTO field generation where no route exists at all.Side effect worth noting: the
ParamType.PATH: "FromPath"entry was previously unreachable, since nothing could setparam_typetoPATHon a value reaching this function. It becomes reachable throughPathParameter().Tests
Three tests added to
tests/unit/test_typing.py:test_kwarg_definition_as_default_without_explicit_source_suggests_parameter— covers the reported bug, and fails without the fix.test_kwarg_definition_as_default_suggests_dedicated_alias— the four dedicated subclasses still name their alias, includingFromPath.test_kwarg_definition_as_default_with_explicit_source_suggests_dedicated_alias— the deprecatedheader=/cookie=/query=kwargs still name their alias.608 tests pass across
test_typing,test_kwargs,test_signatureandtest_openapi. ruff, mypy, pyright and slotscheck are clean.