From 93a4ec55db65aeaa1a60d43c1c5f542fe1a0a3f6 Mon Sep 17 00:00:00 2001 From: Miguel Monteiro Date: Sun, 6 Oct 2024 16:54:16 +0000 Subject: [PATCH 1/3] fix: empty tuples are correctly parsed --- jsonargparse/_typehints.py | 2 +- jsonargparse_tests/test_typehints.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/jsonargparse/_typehints.py b/jsonargparse/_typehints.py index 445026c3..ab86635f 100644 --- a/jsonargparse/_typehints.py +++ b/jsonargparse/_typehints.py @@ -848,7 +848,7 @@ def adapt_typehints( subtypehint = subtypehints[0 if is_ellipsis or not is_tuple else n] val[n] = adapt_typehints(v, subtypehint, **adapt_kwargs) if is_tuple and len(val) == 0: - raise_unexpected_value("Expected a non-empty tuple", val) + val = () if not serialize: val = tuple(val) if typehint_origin in {Tuple, tuple} else set(val) diff --git a/jsonargparse_tests/test_typehints.py b/jsonargparse_tests/test_typehints.py index 86c83749..21bf766d 100644 --- a/jsonargparse_tests/test_typehints.py +++ b/jsonargparse_tests/test_typehints.py @@ -286,7 +286,7 @@ def test_tuple_ellipsis(parser): parser.add_argument("--tuple", type=Tuple[float, ...]) assert (1.2,) == parser.parse_args(["--tuple=[1.2]"]).tuple assert (1.2, 3.4) == parser.parse_args(["--tuple=[1.2, 3.4]"]).tuple - pytest.raises(ArgumentError, lambda: parser.parse_args(["--tuple=[]"])) + assert () == parser.parse_args(["--tuple=[]"]).tuple pytest.raises(ArgumentError, lambda: parser.parse_args(['--tuple=[2, "a"]'])) From dc54d5b84b25d60b9952773bdfa4eb3e998f47d2 Mon Sep 17 00:00:00 2001 From: Miguel Monteiro Date: Wed, 9 Oct 2024 14:43:22 +0000 Subject: [PATCH 2/3] fix: empty tuples are now parsed correctly --- CHANGELOG.rst | 10 ++++++++++ jsonargparse/_typehints.py | 2 -- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 7aebe336..a9883b10 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -12,6 +12,16 @@ The semantic versioning only considers the public API as described in paths are considered internals and can change in minor and patch releases. +v4.33.2 (2024-10-09) +-------------------- + +Fixed +^^^^^ +- Empty tuples are now parsed correctly instead of raising an error. + (`#592 Date: Wed, 9 Oct 2024 17:21:30 +0200 Subject: [PATCH 3/3] Update CHANGELOG.rst --- CHANGELOG.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 770d59d6..ade9d057 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -12,7 +12,7 @@ The semantic versioning only considers the public API as described in paths are considered internals and can change in minor and patch releases. -v4.33.3 (2024-10-09) +v4.33.3 (2024-10-??) -------------------- Fixed