Skip to content
Merged
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
9 changes: 9 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ The semantic versioning only considers the public API as described in
paths are considered internals and can change in minor and patch releases.


v4.27.4 (2024-01-??)
--------------------

Fixed
^^^^^
- ``argcomplete`` not working when type and choices given (`#442
<https://github.com/omni-us/jsonargparse/issues/442>`__).


v4.27.3 (2024-01-26)
--------------------

Expand Down
4 changes: 3 additions & 1 deletion jsonargparse/_typehints.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,9 @@ def extra_help(self):

def completer(self, prefix, **kwargs):
"""Used by argcomplete, validates value and shows expected type."""
if self._typehint == bool:
if self.choices:
return [str(c) for c in self.choices]
elif self._typehint == bool:
return ["true", "false"]
elif is_optional(self._typehint, bool):
return ["true", "false", "null"]
Expand Down
7 changes: 7 additions & 0 deletions jsonargparse_tests/test_argcomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,13 @@ class EnumType(Enum):
assert err == ""


def test_str_with_choices(parser):
parser.add_argument("--str", type=str, choices=["xyz", "abc"])
out, err = complete_line(parser, "tool.py --str=")
assert out == "xyz\x0babc"
assert err == ""


@skip_if_not_cpython
@skip_if_jsonschema_unavailable
def test_action_jsonschema(parser):
Expand Down