Skip to content

Commit 08df485

Browse files
committed
Review comment
1 parent 6f3e36d commit 08df485

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

‎jsonargparse/_util.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,8 @@ def import_object(name: str, check_path: bool = True):
316316
annotation, instead of from a parsed value.
317317
"""
318318
if isinstance(name, str) and name in code_given_classes:
319+
if check_path:
320+
check_import_path(name)
319321
return code_given_classes[name]
320322
if not isinstance(name, str) or "." not in name:
321323
raise ValueError(f"Expected a dot import path string: {name}")

‎jsonargparse_tests/test_import_paths.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,19 @@ def test_subclass_class_path_denied_by_default(parser):
356356
parser.parse_args(["--handler=logging.FileHandler"])
357357

358358

359+
def test_subclass_class_path_of_local_class_denied(parser):
360+
class LocalCalendar(Calendar):
361+
pass
362+
363+
parser.add_argument("--local", type=LocalCalendar)
364+
parser.add_argument("--cal", type=Calendar)
365+
cfg = parser.parse_args(["--local={}"])
366+
assert cfg.local.class_path.endswith("<locals>.LocalCalendar")
367+
set_parsing_settings(import_path_denylist=[__name__])
368+
with pytest.raises(ArgumentError, match="not allowed"):
369+
parser.parse_args([f"--cal={cfg.local.class_path}"])
370+
371+
359372
def test_star_callable_bound_to_denied_callable_denied(parser):
360373
set_parsing_settings(import_path_denylist=["*"], import_path_allowlist=["jsonargparse_tests"])
361374
parser.add_argument("--fn", type=Callable)

0 commit comments

Comments
 (0)