Skip to content

Commit 8ce269b

Browse files
authored
Fix some deprecations not shown in the API documentation (#760)
1 parent bde53d9 commit 8ce269b

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

CHANGELOG.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ Fixed
2727
- Improved parameter kind handling for argument requirement determination.
2828
``KEYWORD_ONLY`` parameters now correctly use ``--flag`` style (`#756
2929
<https://github.com/omni-us/jsonargparse/pull/756>`__).
30+
- Some deprecations not shown in the API documentation (`#760
31+
<https://github.com/omni-us/jsonargparse/pull/760>`__).
3032

3133
Changed
3234
^^^^^^^

jsonargparse/_deprecated.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
"ActionOperators",
2323
"ActionPath",
2424
"ActionPathList",
25+
"HelpFormatterDeprecations",
2526
"LoggerProperty",
27+
"ParserDeprecations",
2628
"ParserError",
2729
"get_config_read_mode",
2830
"namespace_to_dict",
@@ -462,6 +464,8 @@ def path_skip_check_deprecation(stacklevel=2):
462464

463465

464466
class PathDeprecations:
467+
"""Deprecated methods for Path."""
468+
465469
@property
466470
def rel_path(self):
467471
deprecation_warning("Path attr get", path_immutable_attrs_message)
@@ -548,11 +552,14 @@ def deprecation_warning_error_handler(stacklevel):
548552

549553

550554
class ParserDeprecations:
555+
"""Helper class for ArgumentParser deprecations. Will be removed in v5.0.0."""
556+
551557
def __init__(self, *args, error_handler=False, **kwargs):
552558
super().__init__(*args, **kwargs)
553559
self.error_handler = error_handler
554560

555561
@property
562+
@deprecated("error_handler property is deprecated and will be removed in v5.0.0.")
556563
def error_handler(self) -> Optional[Callable[[ArgumentParser, str], None]]:
557564
"""Property for the error_handler function that is called when there are parsing errors.
558565
@@ -704,6 +711,8 @@ def namespace_to_dict(namespace: Namespace) -> Dict[str, Any]:
704711

705712

706713
class HelpFormatterDeprecations:
714+
"""Helper class for DefaultHelpFormatter deprecations. Will be removed in v5.0.0."""
715+
707716
def __init__(self, *args, **kwargs):
708717
from jsonargparse._formatters import YAMLCommentFormatter
709718

jsonargparse_tests/test_deprecated.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,13 @@ def test_error_handler_parameter():
345345
message="error_handler was deprecated in v4.20.0",
346346
code=code,
347347
)
348-
assert parser.error_handler == usage_and_exit_error_handler
348+
with catch_warnings(record=True) as w:
349+
assert parser.error_handler == usage_and_exit_error_handler
350+
assert_deprecation_warn(
351+
w,
352+
message="error_handler property is deprecated",
353+
code="parser.error_handler",
354+
)
349355
with suppress_stderr(), pytest.raises(SystemExit), catch_warnings(record=True):
350356
parser.parse_args(["--invalid"])
351357

@@ -363,7 +369,13 @@ def custom_error_handler(self, message):
363369
message="error_handler was deprecated in v4.20.0",
364370
code="parser.error_handler = custom_error_handler",
365371
)
366-
assert parser.error_handler == custom_error_handler
372+
with catch_warnings(record=True) as w:
373+
assert parser.error_handler == custom_error_handler
374+
assert_deprecation_warn(
375+
w,
376+
message="error_handler property is deprecated",
377+
code="parser.error_handler",
378+
)
367379

368380
out = StringIO()
369381
with redirect_stdout(out), pytest.raises(SystemExit):

0 commit comments

Comments
 (0)