Conversation
…rd-only args process_arg_type_annotation takes (arg, default_value), and the two positional branches of process_args pass it. The two keyword-only branches called it with only the arg, so any pipeline signature containing a keyword-only parameter raised TypeError instead of producing its schema. Also guard the default itself: ast keeps a None placeholder in kw_defaults for keyword-only args declared without a default, so read it through convert_to_value (as the positional branch does) and report has_default accordingly instead of unconditionally True + dft.value.
This branch has not been deployed
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.
The bug
process_arg_type_annotationtakes two required parameters:process_argshas four call sites. The two positional-argument branches pass both parameters; the two keyword-only branches pass only one:process_arg_type_annotation(arg, None)✅process_arg_type_annotation(arg, value)✅process_arg_type_annotation(kwarg)❌process_arg_type_annotation(kwarg)❌So any pipeline whose signature contains a keyword-only parameter fails schema generation with:
The second half of the same bug
Fixing only the arity is not enough.
astkeeps aNoneplaceholder inkw_defaultsfor every keyword-only arg declared without a default, solen(args.kw_defaults) == len(args.kwonlyargs)always holds. That makesn_kwargs - n_kwargs_defaultalways0, so:dft.valueand appendshas_default=True, which wouldAttributeErroron theNoneplaceholder and mislabel a required kw-only arg as optional.So the fix reads the default through
convert_to_value— exactly what the positional branch at line 304 already does — and deriveshas_defaultfrom whether a default is actually present.Verification
Ran against the real
modelscope.utils.input_output(no stubs), before and after:Three tests added as
ProcessArgsTestintests/utils/test_input_output.py. The two keyword-only tests error onmasterwith the exactTypeError; the positional test passes both before and after, pinning that the existing path is untouched:yapf==0.30.0(the pinned pre-commit rev) reports no diff on either file,isortis clean, andflake8with thesetup.cfgselect/ignoreset reports nothing new.Out of scope, but noticed while verifying
convert_to_valueends inreturn UnhandledKeyType(), andUnhandledKeyTypeis not defined anywhere in the repo — so a non-literal default (e.g.def f(self, a: list = [1, 2])) raisesNameError: name 'UnhandledKeyType' is not defined. That is pre-existing on the positional path and reproduces onmasterwithout this patch, so I left it alone rather than guessing at the intended sentinel type. Happy to send a follow-up if you tell me what it should return.🤖 Generated with Claude Code