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
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Fixed
- Improved parameter kind handling for argument requirement determination.
``KEYWORD_ONLY`` parameters now correctly use ``--flag`` style (`#756
<https://github.com/omni-us/jsonargparse/pull/756>`__).
- Some deprecations not shown in the API documentation (`#760
<https://github.com/omni-us/jsonargparse/pull/760>`__).

Changed
^^^^^^^
Expand Down
9 changes: 9 additions & 0 deletions jsonargparse/_deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
"ActionOperators",
"ActionPath",
"ActionPathList",
"HelpFormatterDeprecations",
"LoggerProperty",
"ParserDeprecations",
"ParserError",
"get_config_read_mode",
"namespace_to_dict",
Expand Down Expand Up @@ -462,6 +464,8 @@ def path_skip_check_deprecation(stacklevel=2):


class PathDeprecations:
"""Deprecated methods for Path."""

@property
def rel_path(self):
deprecation_warning("Path attr get", path_immutable_attrs_message)
Expand Down Expand Up @@ -548,11 +552,14 @@ def deprecation_warning_error_handler(stacklevel):


class ParserDeprecations:
"""Helper class for ArgumentParser deprecations. Will be removed in v5.0.0."""

def __init__(self, *args, error_handler=False, **kwargs):
super().__init__(*args, **kwargs)
self.error_handler = error_handler

@property
@deprecated("error_handler property is deprecated and will be removed in v5.0.0.")
def error_handler(self) -> Optional[Callable[[ArgumentParser, str], None]]:
"""Property for the error_handler function that is called when there are parsing errors.

Expand Down Expand Up @@ -704,6 +711,8 @@ def namespace_to_dict(namespace: Namespace) -> Dict[str, Any]:


class HelpFormatterDeprecations:
"""Helper class for DefaultHelpFormatter deprecations. Will be removed in v5.0.0."""

def __init__(self, *args, **kwargs):
from jsonargparse._formatters import YAMLCommentFormatter

Expand Down
16 changes: 14 additions & 2 deletions jsonargparse_tests/test_deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,13 @@ def test_error_handler_parameter():
message="error_handler was deprecated in v4.20.0",
code=code,
)
assert parser.error_handler == usage_and_exit_error_handler
with catch_warnings(record=True) as w:
assert parser.error_handler == usage_and_exit_error_handler
assert_deprecation_warn(
w,
message="error_handler property is deprecated",
code="parser.error_handler",
)
with suppress_stderr(), pytest.raises(SystemExit), catch_warnings(record=True):
parser.parse_args(["--invalid"])

Expand All @@ -363,7 +369,13 @@ def custom_error_handler(self, message):
message="error_handler was deprecated in v4.20.0",
code="parser.error_handler = custom_error_handler",
)
assert parser.error_handler == custom_error_handler
with catch_warnings(record=True) as w:
assert parser.error_handler == custom_error_handler
assert_deprecation_warn(
w,
message="error_handler property is deprecated",
code="parser.error_handler",
)

out = StringIO()
with redirect_stdout(out), pytest.raises(SystemExit):
Expand Down
Loading