Skip to content

Commit

Permalink
fix: broken support for Optional[List] (fixes #216)
Browse files Browse the repository at this point in the history
  • Loading branch information
neithere committed Jan 23, 2024
1 parent 278a840 commit 29991d3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Changelog
=========

Version 0.31.2 (2024-01-23)
---------------------------

Bugs fixed:

- broken support for `Optional[List]` (but not `Optional[list]`), a narrower
case of the problem fixed earlier (issue #216).

Version 0.31.1 (2024-01-19)
---------------------------

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "flit_core.buildapi"

[project]
name = "argh"
version = "0.31.1"
version = "0.31.2"
description = "Plain Python functions as CLI commands without boilerplate"
readme = "README.rst"
requires-python = ">=3.8"
Expand Down
4 changes: 2 additions & 2 deletions src/argh/assembling.py
Original file line number Diff line number Diff line change
Expand Up @@ -770,10 +770,10 @@ def typing_hint_to_arg_spec_params(
if first_subtype in cls.BASIC_TYPES:
retval["type"] = first_subtype

if first_subtype == list:
if first_subtype in (list, List):
retval["nargs"] = ZERO_OR_MORE

if get_origin(first_subtype) == list:
if first_subtype != List and get_origin(first_subtype) == list:
retval["nargs"] = ZERO_OR_MORE
item_type = cls._extract_item_type_from_list_type(first_subtype)
if item_type:
Expand Down
1 change: 1 addition & 0 deletions tests/test_typing_hints.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def test_list():
assert guess(list) == {"nargs": "*"}
assert guess(List) == {"nargs": "*"}
assert guess(Optional[list]) == {"nargs": "*", "required": False}
assert guess(Optional[List]) == {"nargs": "*", "required": False}

assert guess(List[str]) == {"nargs": "*", "type": str}
assert guess(List[int]) == {"nargs": "*", "type": int}
Expand Down

0 comments on commit 29991d3

Please sign in to comment.