Skip to content

Commit

Permalink
For consistency add_subclass_arguments now sets default None instead …
Browse files Browse the repository at this point in the history
…of SUPPRESS (lightning#20103).
  • Loading branch information
mauvilsa committed Sep 10, 2024
1 parent 9919b35 commit fc14b3e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.0 (2024-09-??)
--------------------

Changed
^^^^^^^
- For consistency ``add_subclass_arguments`` now sets default ``None`` instead
of ``SUPPRESS`` (`lightning#20103
<https://github.com/Lightning-AI/pytorch-lightning/issue/20103>`__).


v4.32.2 (2024-09-??)
--------------------

Expand Down
4 changes: 2 additions & 2 deletions jsonargparse/_signatures.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import dataclasses
import inspect
import re
from argparse import SUPPRESS, ArgumentParser
from argparse import ArgumentParser
from contextlib import suppress
from typing import Any, Callable, List, Optional, Set, Tuple, Type, Union

Expand Down Expand Up @@ -549,7 +549,7 @@ def add_subclass_arguments(
}
)
if "default" not in kwargs:
kwargs["default"] = SUPPRESS
kwargs["default"] = None
self._add_signature_parameter(
group, None, param, added_args, skip, sub_configs=True, instantiate=instantiate, **kwargs
)
Expand Down
4 changes: 1 addition & 3 deletions jsonargparse_tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,9 +760,7 @@ def test_default_config_files(parser, subtests, tmp_cwd):
with subtests.test("get_default"):
assert parser.get_default("op1") == "from default config file"
parser.add_subclass_arguments(Calendar, "cal")
with pytest.raises(KeyError) as ctx:
parser.get_default("cal")
ctx.match("does not specify a default")
assert parser.get_default("cal") is None

with subtests.test("set invalid"):
with pytest.raises(ValueError) as ctx:
Expand Down
6 changes: 3 additions & 3 deletions jsonargparse_tests/test_subclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -1338,9 +1338,9 @@ def test_add_subclass_required_group(parser):
def test_add_subclass_not_required_group(parser):
parser.add_subclass_arguments(Calendar, "cal", required=False)
cfg = parser.parse_args([])
assert cfg == Namespace()
assert cfg == Namespace(cal=None)
init = parser.instantiate_classes(cfg)
assert init == Namespace()
assert init == Namespace(cal=None)


class ListUnionA:
Expand Down Expand Up @@ -1723,7 +1723,7 @@ def test_subclass_error_indentation_invalid_init_arg(parser):
Given value: abc
"""
).strip()
expected = textwrap.indent(expected, " ")
expected = textwrap.indent(expected, " ")
assert expected in err


Expand Down

0 comments on commit fc14b3e

Please sign in to comment.