diff --git a/CHANGELOG.rst b/CHANGELOG.rst index a9361da2..36ebe68e 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -26,9 +26,10 @@ Fixed ^^^^^ - Callable type with subclass return not showing the ``--*.help`` option (`#567 `__). - - Forward referenced types not compatible with `Type` typehint (`#576 - `__) + `__). +- Subclass nested in ``Iterable`` makes help fail (`#578 + `__). Changed ^^^^^^^ diff --git a/jsonargparse/_typehints.py b/jsonargparse/_typehints.py index b1a20bcf..50a119b8 100644 --- a/jsonargparse/_typehints.py +++ b/jsonargparse/_typehints.py @@ -1226,7 +1226,7 @@ def is_private(class_path): return "._" in class_path def add_subclasses(cl): - if hasattr(cl, "__args__") and get_typehint_origin(cl) in {List, list, Union}: + if hasattr(cl, "__args__") and get_typehint_origin(cl) in sequence_origin_types.union({Union}): for arg in cl.__args__: add_subclasses(arg) return diff --git a/jsonargparse_tests/test_subclasses.py b/jsonargparse_tests/test_subclasses.py index 3d5d8149..a5a4d379 100644 --- a/jsonargparse_tests/test_subclasses.py +++ b/jsonargparse_tests/test_subclasses.py @@ -742,12 +742,14 @@ def __init__(self, p1: int = 0, p2: int = 0): pass -def test_subclass_list_append_single(parser): - parser.add_argument("--val", type=Union[ListAppend, List[ListAppend]]) +@pytest.mark.parametrize("list_type", [List, Iterable]) +def test_subclass_list_append_single(parser, list_type): + parser.add_argument("--val", type=Union[ListAppend, list_type[ListAppend]]) cfg = parser.parse_args([f"--val+={__name__}.ListAppend", "--val.p1=1", "--val.p2=2", "--val.p1=3"]) assert cfg.val == [Namespace(class_path=f"{__name__}.ListAppend", init_args=Namespace(p1=3, p2=2))] cfg = parser.parse_args(["--val+=ListAppend", "--val.p2=2", "--val.p1=1"]) assert cfg.val == [Namespace(class_path=f"{__name__}.ListAppend", init_args=Namespace(p1=1, p2=2))] + assert " --val+ " in get_parser_help(parser) @final