From 01eead8ac7e8573f58f910d478c42bb0dcc592bd Mon Sep 17 00:00:00 2001 From: Mauricio Villegas <5780272+mauvilsa@users.noreply.github.com> Date: Thu, 29 Jan 2026 08:35:29 +0100 Subject: [PATCH] Added unit test for union of path or dict --- jsonargparse_tests/test_paths.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/jsonargparse_tests/test_paths.py b/jsonargparse_tests/test_paths.py index f2650ab3..ccc03a62 100644 --- a/jsonargparse_tests/test_paths.py +++ b/jsonargparse_tests/test_paths.py @@ -714,5 +714,21 @@ def test_sub_configs_union_subclass_and_pathlike(parser, tmp_cwd): assert cfg.data.path == str(data_path) +def test_union_path_or_dict(parser, tmp_cwd): + arg_path = pathlib.Path("arg.json") + arg_path.touch() + + parser.add_argument("--arg", type=Union[Path_fr, dict]) + + cfg = parser.parse_args([f"--arg={arg_path}"]) + assert isinstance(cfg.arg, Path_fr) + assert str(arg_path) == str(cfg.arg) + + cfg = parser.parse_args(['--arg={"key": "value"}']) + assert cfg.arg == {"key": "value"} + + def test_import_old_path_location(): - from jsonargparse import Path # noqa: F401 + from jsonargparse import Path as path_old + + assert path_old is Path