Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ ci:
skip:
- twine-check
- changelog-bump
autofix_prs: false
autofix_prs: true
autoupdate_schedule: quarterly

repos:

Expand All @@ -24,12 +25,12 @@ repos:
exclude: .bumpversion.cfg

- repo: https://github.com/psf/black
rev: 25.12.0
rev: 26.1.0
hooks:
- id: black

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.14.10
rev: v0.14.13
hooks:
- id: ruff
args: ["--fix"]
Expand All @@ -40,7 +41,7 @@ repos:
- id: yesqa

- repo: https://github.com/crate-ci/typos
rev: v1.41.0
rev: v1.42.1
hooks:
- id: typos
args: []
Expand Down
114 changes: 38 additions & 76 deletions jsonargparse/_deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,10 @@ def patched_save(self, cfg: Union[Namespace, Dict[str, Any]], *args, multifile:
ArgumentParser.save = patched_save


@deprecated(
"""
@deprecated("""
ActionEnum was deprecated in v3.9.0 and will be removed in v5.0.0. Enums now
should be given directly as a type as explained in :ref:`enums`.
"""
)
""")
class ActionEnum:
"""An action based on an Enum that maps to-from strings and enum values."""

Expand All @@ -215,12 +213,10 @@ def __call__(self, *args, **kwargs):
return ActionTypeHint(typehint=self._type)(**kwargs)


@deprecated(
"""
@deprecated("""
ActionOperators was deprecated in v3.0.0 and will be removed in v5.0.0. Now
types should be used as explained in :ref:`restricted-numbers`.
"""
)
""")
class ActionOperators:
"""Action to restrict a value with comparison operators."""

Expand All @@ -245,12 +241,10 @@ def __call__(self, *args, **kwargs):
return ActionTypeHint(typehint=self._type)(**kwargs)


@deprecated(
"""
@deprecated("""
ActionPath was deprecated in v3.11.0 and will be removed in v5.0.0. Paths
now should be given directly as a type as explained in :ref:`parsing-paths`.
"""
)
""")
class ActionPath:
"""Action to check and store a path."""

Expand All @@ -269,12 +263,10 @@ def __call__(self, *args, **kwargs):
return ActionTypeHint(typehint=self._type)(**kwargs)


@deprecated(
"""
@deprecated("""
ActionPathList was deprecated in v4.20.0 and will be removed in v5.0.0. Instead
use as type ``List[<path_type>]`` with ``enable_path=True``.
"""
)
""")
class ActionPathList(Action):
"""Action to check and store a list of file paths read from a plain text file or stream."""

Expand Down Expand Up @@ -351,13 +343,11 @@ def _check_type(self, value):
return value


@deprecated(
"""
@deprecated("""
set_url_support was deprecated in v3.12.0 and will be removed in v5.0.0.
Optional config read modes should now be set using function
set_parsing_settings.
"""
)
""")
def set_url_support(enabled: bool):
"""Enables/disables URL support for config read mode."""
from ._optionals import _get_config_read_mode, _set_config_read_mode
Expand All @@ -368,13 +358,11 @@ def set_url_support(enabled: bool):
)


@deprecated(
"""
@deprecated("""
set_config_read_mode was deprecated in v4.39.0 and will be removed in
v5.0.0. Optional config read modes should now be set using function
set_parsing_settings.
"""
)
""")
def set_config_read_mode(
urls_enabled: bool = False,
fsspec_enabled: bool = False,
Expand All @@ -388,26 +376,22 @@ def set_config_read_mode(
)


@deprecated(
"""
@deprecated("""
get_config_read_mode was deprecated in v4.39.0 and will be removed in
v5.0.0. The config read mode is internal and thus shouldn't be used.
"""
)
""")
def get_config_read_mode() -> str:
"""Returns the current config reading mode."""
from ._optionals import _get_config_read_mode

return _get_config_read_mode()


@deprecated(
"""
@deprecated("""
set_docstring_parse_options was deprecated in v4.39.0 and will be removed in
v5.0.0. Docstring parse options should now be set using function
set_parsing_settings.
"""
)
""")
def set_docstring_parse_options(style=None, attribute_docstrings: Optional[bool] = None):
"""Sets options for docstring parsing."""
from ._optionals import _set_docstring_parse_options
Expand Down Expand Up @@ -526,13 +510,11 @@ class DebugException(Exception):
pass


@deprecated(
"""
@deprecated("""
usage_and_exit_error_handler was deprecated in v4.20.0 and will be removed
in v5.0.0. With the removal of error_handler, there is no longer a need for
this function.
"""
)
""")
def usage_and_exit_error_handler(parser: ArgumentParser, message: str) -> None:
"""Prints the usage and exits with error code 2 (same behavior as argparse).

Expand Down Expand Up @@ -621,32 +603,26 @@ def default_meta(self, default_meta: bool):
else:
raise ValueError("default_meta expects a boolean.")

@deprecated(
"""
@deprecated("""
instantiate_subclasses was deprecated in v4.0.0 and will be removed in v5.0.0.
Instead use instantiate_classes.
"""
)
""")
def instantiate_subclasses(self, cfg: Namespace) -> Namespace:
return self.instantiate_classes(cfg, instantiate_groups=False) # type: ignore[attr-defined]

@deprecated(
"""
@deprecated("""
add_dataclass_arguments was deprecated in v4.35.0 and will be removed in
v5.0.0. Instead use add_class_arguments.
"""
)
""")
def add_dataclass_arguments(self, *args, **kwargs):
if "title" in kwargs:
kwargs["help"] = kwargs.pop("title")
return self.add_class_arguments(*args, **kwargs)

@deprecated(
"""
@deprecated("""
ArgumentParser.check_config was deprecated in v4.35.0 and will be removed in
v5.0.0. Instead use validate.
"""
)
""")
def check_config(self, *args, **kwargs):
return self.validate(*args, **kwargs)

Expand Down Expand Up @@ -691,14 +667,12 @@ def deprecated_module(module_name, mappings=None):
module = ModuleType(module_path, f"deprecated {module_path}")
sys.modules[module_path] = module

@deprecated(
f"""
@deprecated(f"""
Only use the public API as described in
https://jsonargparse.readthedocs.io/en/stable/#api-reference. Importing
from {module_path} is kept only to avoid breaking code that does not
correctly use the public API. It will no longer be available from v5.0.0.
"""
)
""")
def __getattr__(name):
new_module = f"_{module_name}"
if mappings and name in mappings:
Expand Down Expand Up @@ -732,12 +706,10 @@ def __getattr__(name):
)


@deprecated(
"""
@deprecated("""
ActionJsonnetExtVars was deprecated in v4.24.0 and will be removed in
v5.0.0. Instead use ``type=dict``.
"""
)
""")
class ActionJsonnetExtVars:
"""Action to add argument to provide ext_vars for jsonnet parsing."""

Expand All @@ -749,36 +721,30 @@ def __call__(self, *args, **kwargs):
return action


@deprecated(
"""
@deprecated("""
LoggerProperty was deprecated in v4.40.0 and will be removed from the public
API in v5.0.0. There is no replacement since jsonargparse is not a logging
library. A similar class can be found in reconplogger package.
"""
)
""")
class LoggerProperty(InternalLoggerProperty):
"""Adds a logger property, intended for internal use."""


@deprecated(
"""
@deprecated("""
namespace_to_dict was deprecated in v4.40.0 and will be removed in v5.0.0.
Instead you can use ``.clone().as_dict()`` or ``.as_dict()``.
"""
)
""")
def namespace_to_dict(namespace: Namespace) -> Dict[str, Any]:
"""Returns a copy of a nested namespace converted into a nested dictionary."""
return namespace.clone().as_dict()


@deprecated(
"""
@deprecated("""
dict_to_namespace was deprecated in v4.43.0 and will be removed in v5.0.0.
No replacement is provided because blindly converting a dictionary to a
namespace may not yield the same results as using a parser, which could lead
to confusion.
"""
)
""")
def dict_to_namespace(cfg_dict: dict[str, Any]) -> Namespace:
"""Converts a nested dictionary into a nested namespace."""
from ._namespace import dict_to_namespace as _dict_to_namespace
Expand All @@ -794,12 +760,10 @@ def strip_meta(cfg: "Namespace") -> "Namespace": ... # pragma: no cover
def strip_meta(cfg: Dict[str, Any]) -> Dict[str, Any]: ... # pragma: no cover


@deprecated(
"""
@deprecated("""
strip_meta was deprecated in v4.43.0 and will be removed in v5.0.0.
Instead use ``.clone(with_meta=False)``.
"""
)
""")
def strip_meta(cfg):
"""Removes all metadata keys from a configuration object."""
from ._namespace import remove_meta
Expand Down Expand Up @@ -856,13 +820,11 @@ def set_yaml_argument_comment(self, text: str, cfg: ruamelCommentedMap, key: str
self._yaml_formatter.set_yaml_argument_comment(text, cfg, key, depth)


@deprecated(
"""
@deprecated("""
compose_dataclasses is deprecated and will be removed in v5.0.0. There is
no direct replacement, whoever is interested can copy the code from an old
release.
"""
)
""")
def compose_dataclasses(*args):
"""Returns a dataclass inheriting all given dataclasses and properly handling __post_init__."""

Expand Down
12 changes: 4 additions & 8 deletions jsonargparse_tests/test_subclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -1838,8 +1838,7 @@ def __init__(self, val: Optional[Union[int, dict]] = None):
def test_subclass_error_indentation_invalid_init_arg(parser):
parser.add_subclass_arguments(ErrorIndentation1, "cls")
err = get_parse_args_stderr(parser, ["--cls=ErrorIndentation1", "--cls.init_args.val=abc"])
expected = textwrap.dedent(
"""
expected = textwrap.dedent("""
Parser key "val":
Does not validate against any of the Union subtypes
Subtypes: [<class 'NoneType'>, <class 'int'>, <class 'dict'>]
Expand All @@ -1849,8 +1848,7 @@ def test_subclass_error_indentation_invalid_init_arg(parser):
- Expected a <class 'dict'>
Given value type: <class 'str'>
Given value: abc
"""
).strip()
""").strip()
expected = textwrap.indent(expected, " ")
assert "\n".join(expected.splitlines()) in "\n".join(err.splitlines())

Expand All @@ -1865,8 +1863,7 @@ def test_subclass_error_indentation_in_union_invalid_value(parser):
parser.add_argument("--cfg", action="config")
config = {"union": [{"class_path": "ErrorIndentation2", "init_args": {"val": "x"}}]}
err = get_parse_args_stderr(parser, [f"--cfg={json.dumps(config)}"])
expected = textwrap.dedent(
"""
expected = textwrap.dedent("""
Errors:
- Expected a <class 'str'>
- Not a valid subclass of ErrorIndentation2
Expand All @@ -1877,7 +1874,6 @@ def test_subclass_error_indentation_in_union_invalid_value(parser):
- a dict with parameters accepted by the base class (implicit class_path)
Given value type: <class 'list'>
Given value: [{'class_path': 'ErrorIndentation2', 'init_args': {'val': 'x'}}]
"""
).strip()
""").strip()
expected = textwrap.indent(expected, " ")
assert "\n".join(expected.splitlines()) in "\n".join(err.splitlines())
Loading