From 29991d310925319c9e344a0e8453c904163e9aad Mon Sep 17 00:00:00 2001 From: Andy Mikhaylenko Date: Tue, 23 Jan 2024 11:21:53 +0100 Subject: [PATCH 1/3] fix: broken support for `Optional[List]` (fixes #216) --- CHANGELOG.rst | 8 ++++++++ pyproject.toml | 2 +- src/argh/assembling.py | 4 ++-- tests/test_typing_hints.py | 1 + 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index f35dd60..e64eccd 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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) --------------------------- diff --git a/pyproject.toml b/pyproject.toml index 00db708..9861179 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" diff --git a/src/argh/assembling.py b/src/argh/assembling.py index 02aefe5..7a690ea 100644 --- a/src/argh/assembling.py +++ b/src/argh/assembling.py @@ -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: diff --git a/tests/test_typing_hints.py b/tests/test_typing_hints.py index 2432824..6114edc 100644 --- a/tests/test_typing_hints.py +++ b/tests/test_typing_hints.py @@ -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} From 8b2191fdb26967db453695233ab1e4ba90ae497f Mon Sep 17 00:00:00 2001 From: Andy Mikhaylenko Date: Tue, 23 Jan 2024 11:38:15 +0100 Subject: [PATCH 2/3] docs: update Sphinx/RTD dependencies --- pyproject.toml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 9861179..90f9f80 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -59,10 +59,10 @@ test = [ "pytest-cov >= 4.1", ] docs = [ - "sphinx >= 6.1", - "sphinx-pyproject == 0.1.0", - "sphinx_rtd_theme >= 1.2.0", - "readthedocs-sphinx-search == 0.2.0", + "sphinx >= 7.2", + "sphinx-pyproject == 0.3", + "sphinx_rtd_theme >= 2.0", + "readthedocs-sphinx-search == 0.3.2", ] linters = [ "pre-commit >= 3.4.0", From 9d4da94f53d6e5cde1988f62a06ab1726ab5d36e Mon Sep 17 00:00:00 2001 From: Andy Mikhaylenko Date: Wed, 24 Jan 2024 22:23:27 +0100 Subject: [PATCH 3/3] chore: bump release date --- CHANGELOG.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index e64eccd..ef2a548 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,7 +1,7 @@ Changelog ========= -Version 0.31.2 (2024-01-23) +Version 0.31.2 (2024-01-24) --------------------------- Bugs fixed: