Skip to content

Commit

Permalink
Fix help incorrectly showing protocols in known subclasses (#638)
Browse files Browse the repository at this point in the history
  • Loading branch information
mauvilsa authored Dec 2, 2024
1 parent 98e03d6 commit dddea47
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Fixed
<https://github.com/omni-us/jsonargparse/pull/625>`__).
- Callable protocols failing to parse (`#637
<https://github.com/omni-us/jsonargparse/pull/637>`__).
- Help incorrectly showing protocols in known subclasses (`#638
<https://github.com/omni-us/jsonargparse/pull/638>`__).


v4.34.0 (2024-11-08)
Expand Down
2 changes: 1 addition & 1 deletion jsonargparse/_typehints.py
Original file line number Diff line number Diff line change
Expand Up @@ -1267,7 +1267,7 @@ def add_subclasses(cl):
return
if is_local(cl) or is_subclass(cl, LazyInitBaseClass):
return
if not (inspect.isabstract(cl) or is_private(class_path)):
if not (inspect.isabstract(cl) or is_private(class_path) or is_protocol(cl)):
if class_path in subclass_list:
return
subclass_list.append(class_path)
Expand Down
2 changes: 2 additions & 0 deletions jsonargparse_tests/test_subclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -1485,6 +1485,7 @@ def test_is_instance_or_supports_protocol(expected, value):

def test_parse_implements_protocol(parser):
parser.add_argument("--cls", type=Interface)
assert "known subclasses:" not in get_parser_help(parser)
cfg = parser.parse_args([f"--cls={__name__}.ImplementsInterface", "--cls.batch_size=5"])
assert cfg.cls.class_path == f"{__name__}.ImplementsInterface"
assert cfg.cls.init_args == Namespace(batch_size=5)
Expand Down Expand Up @@ -1547,6 +1548,7 @@ def test_implements_callable_protocol(expected, value):

def test_parse_implements_callable_protocol(parser):
parser.add_argument("--cls", type=CallableInterface)
assert "known subclasses:" not in get_parser_help(parser)
cfg = parser.parse_args([f"--cls={__name__}.ImplementsCallableInterface", "--cls.batch_size=7"])
assert cfg.cls.class_path == f"{__name__}.ImplementsCallableInterface"
assert cfg.cls.init_args == Namespace(batch_size=7)
Expand Down

0 comments on commit dddea47

Please sign in to comment.