Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion typer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,10 @@ def get_click_param(
default_value = parameter_info.default
elif param.default == Required or param.default == param.empty:
required = True
parameter_info = ArgumentInfo()
if param.kind == inspect.Parameter.KEYWORD_ONLY:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where should I write the test?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, there would be a tutorial file in docs_src demonstrating the behavior. And then a test for that file in tests/test_tutorial/. Then reference the file in the markdown documentation with a brief explanation.

Sometimes there are tricky edge cases that don't fit into tutorials. In that case, you can add some tests in the top level of the tests/ directory.

parameter_info = OptionInfo()
else:
parameter_info = ArgumentInfo()
else:
default_value = param.default
parameter_info = OptionInfo()
Expand Down
2 changes: 2 additions & 0 deletions typer/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,9 @@ def __init__(
name: str,
default: Any = inspect.Parameter.empty,
annotation: Any = inspect.Parameter.empty,
kind: inspect._ParameterKind = inspect.Parameter.POSITIONAL_OR_KEYWORD,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

accessing inspect._ParameterKind is ugly a bit, but the type name is _ParameterKind
https://github.com/python/typeshed/blob/a690a14c820238ca7a64cd502343d6b5a649e731/stdlib/inspect.pyi#L125-L134

) -> None:
self.name = name
self.default = default
self.annotation = annotation
self.kind = kind
5 changes: 4 additions & 1 deletion typer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ def get_params_from_function(func: Callable[..., Any]) -> Dict[str, ParamMeta]:
if param.name in type_hints:
annotation = type_hints[param.name]
params[param.name] = ParamMeta(
name=param.name, default=param.default, annotation=annotation
name=param.name,
default=param.default,
annotation=annotation,
kind=param.kind,
)
return params