-
Notifications
You must be signed in to change notification settings - Fork 0
Fix lazy commands losing function signature defaults #35
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
Changes from all commits
82f9ace
7e11f27
ce2294f
d929be6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Lazy commands now propagate function signature defaults to argparse. Schema defaults are JSON-safe, boolean schema defaults are respected, and a new `display_result=False` option suppresses plain-format output while preserving `--format json`. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -161,6 +161,10 @@ def function_to_schema(func: Callable[..., Any]) -> dict[str, Any]: | |
| properties[name] = prop | ||
|
|
||
| has_default = param.default is not inspect.Parameter.empty | ||
| if has_default and isinstance( | ||
| param.default, (str, int, float, bool, type(None), list, dict) | ||
| ): | ||
| prop["default"] = param.default | ||
| if not has_default and not is_optional: | ||
|
Comment on lines
163
to
168
|
||
| required.append(name) | ||
|
|
||
|
|
||
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.
Schema defaults are now applied for non-boolean params, but boolean params still compute
defaultasFalsewhen the signature is unavailable (lazy / schema-only mode) because the boolean branch setskwargs["default"]before the new schema-default fallback. This means a precomputed schema like{type: "boolean", default: true}(or a handler defaulting toTruecaptured into schema) will still parse asFalsewhen omitted. Consider usingparam_schema.get("default", False)for booleans whenparamis missing, and ensure the chosen argparseactionis compatible with the intended default.