Skip to content

Commit 15699b1

Browse files
committed
Don't make YAMLCommentFormatter public.
1 parent d20dd1f commit 15699b1

4 files changed

Lines changed: 8 additions & 31 deletions

File tree

CHANGELOG.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ Changed
3131
Deprecated
3232
^^^^^^^^^^
3333
- ``DefaultHelpFormatter.*_yaml*_comment*`` methods are deprecated and will be
34-
removed in v5.0.0. Instead use the new class ``YAMLCommentFormatter`` (`#754
35-
<https://github.com/omni-us/jsonargparse/pull/754>`__).
34+
removed in v5.0.0. This logic has been moved to a new private class
35+
``YAMLCommentFormatter``. If deemed necessary, this class might be made public
36+
in the future (`#754 <https://github.com/omni-us/jsonargparse/pull/754>`__).
3637

3738

3839
v4.40.2 (2025-08-06)

jsonargparse/_deprecated.py

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -710,22 +710,12 @@ def __init__(self, *args, **kwargs):
710710
super().__init__(*args, **kwargs)
711711
self._yaml_formatter = YAMLCommentFormatter(self)
712712

713-
@deprecated(
714-
"""
715-
The add_yaml_comments method is deprecated and will be removed in v5.0.0.
716-
Use :class:`YAMLCommentFormatter` instead.
717-
"""
718-
)
713+
@deprecated("The add_yaml_comments method is deprecated and will be removed in v5.0.0.")
719714
def add_yaml_comments(self, cfg: str) -> str:
720715
"""Adds help text as yaml comments."""
721716
return self._yaml_formatter.add_yaml_comments(cfg)
722717

723-
@deprecated(
724-
"""
725-
The set_yaml_start_comment method is deprecated and will be removed in v5.0.0.
726-
Use :class:`YAMLCommentFormatter` instead.
727-
"""
728-
)
718+
@deprecated("The set_yaml_start_comment method is deprecated and will be removed in v5.0.0.")
729719
def set_yaml_start_comment(self, text: str, cfg: ruyamlCommentedMap):
730720
"""Sets the start comment to a ruyaml object.
731721
@@ -735,12 +725,7 @@ def set_yaml_start_comment(self, text: str, cfg: ruyamlCommentedMap):
735725
"""
736726
self._yaml_formatter.set_yaml_start_comment(text, cfg)
737727

738-
@deprecated(
739-
"""
740-
The set_yaml_group_comment method is deprecated and will be removed in v5.0.0.
741-
Use :class:`YAMLCommentFormatter` instead.
742-
"""
743-
)
728+
@deprecated("The set_yaml_group_comment method is deprecated and will be removed in v5.0.0.")
744729
def set_yaml_group_comment(self, text: str, cfg: ruyamlCommentedMap, key: str, depth: int):
745730
"""Sets the comment for a group to a ruyaml object.
746731
@@ -752,12 +737,7 @@ def set_yaml_group_comment(self, text: str, cfg: ruyamlCommentedMap, key: str, d
752737
"""
753738
self._yaml_formatter.set_yaml_group_comment(text, cfg, key, depth)
754739

755-
@deprecated(
756-
"""
757-
The set_yaml_argument_comment method is deprecated and will be removed in v5.0.0.
758-
Use :class:`YAMLCommentFormatter` instead.
759-
"""
760-
)
740+
@deprecated("The set_yaml_argument_comment method is deprecated and will be removed in v5.0.0.")
761741
def set_yaml_argument_comment(self, text: str, cfg: ruyamlCommentedMap, key: str, depth: int):
762742
"""Sets the comment for an argument to a ruyaml object.
763743

jsonargparse/_formatters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
from ._type_checking import ArgumentParser, ruyamlCommentedMap
3838
from ._typehints import ActionTypeHint, type_to_str
3939

40-
__all__ = ["DefaultHelpFormatter", "YAMLCommentFormatter"]
40+
__all__ = ["DefaultHelpFormatter"]
4141

4242

4343
empty_help: str = "_EMPTY_HELP_"

jsonargparse_tests/test_deprecated.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -745,23 +745,19 @@ def test_DefaultHelpFormatter_yaml_comments(parser):
745745
with catch_warnings(record=True) as w:
746746
formatter.add_yaml_comments("arg: 1")
747747
assert "add_yaml_comments method is deprecated and will be removed in v5.0.0" in str(w[-1].message)
748-
assert ":class:`YAMLCommentFormatter`" in str(w[-1].message)
749748
assert "formatter.add_yaml_comments(" in source[w[-1].lineno - 1]
750749

751750
with catch_warnings(record=True) as w:
752751
formatter.set_yaml_start_comment("start", cfg)
753752
assert "set_yaml_start_comment method is deprecated and will be removed in v5.0.0" in str(w[-1].message)
754-
assert ":class:`YAMLCommentFormatter`" in str(w[-1].message)
755753
assert "formatter.set_yaml_start_comment(" in source[w[-1].lineno - 1]
756754

757755
with catch_warnings(record=True) as w:
758756
formatter.set_yaml_group_comment("group", cfg, "arg", 0)
759757
assert "set_yaml_group_comment method is deprecated and will be removed in v5.0.0" in str(w[-1].message)
760-
assert ":class:`YAMLCommentFormatter`" in str(w[-1].message)
761758
assert "formatter.set_yaml_group_comment(" in source[w[-1].lineno - 1]
762759

763760
with catch_warnings(record=True) as w:
764761
formatter.set_yaml_argument_comment("arg", cfg, "arg", 0)
765762
assert "set_yaml_argument_comment method is deprecated and will be removed in v5.0.0" in str(w[-1].message)
766-
assert ":class:`YAMLCommentFormatter`" in str(w[-1].message)
767763
assert "formatter.set_yaml_argument_comment(" in source[w[-1].lineno - 1]

0 commit comments

Comments
 (0)