Skip to content

Commit

Permalink
Fix cfg.pretty() deprecation warning
Browse files Browse the repository at this point in the history
  • Loading branch information
omry committed Sep 3, 2020
1 parent 3dd16f7 commit 6e0c3d7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions news/358.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix cfg.pretty() deprecation warning
10 changes: 6 additions & 4 deletions omegaconf/basecontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import warnings
from abc import ABC, abstractmethod
from enum import Enum
from textwrap import dedent
from typing import Any, Dict, List, Optional, Tuple, Union

import yaml
Expand Down Expand Up @@ -222,11 +223,12 @@ def pretty(self, resolve: bool = False, sort_keys: bool = False) -> str:
from omegaconf import OmegaConf

warnings.warn(
dedent(
"""\
cfg.pretty() is deprecated and will be removed in a future version.
Use OmegaConf.to_yaml(cfg)
"""
pretty() is deprecated and will be removed in a future version.
Use OmegaConf.to_yaml. Please note that the default value for
resolve has changed to True.
""",
),
category=UserWarning,
)

Expand Down
9 changes: 5 additions & 4 deletions tests/test_to_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,12 @@ def test_pretty_deprecated() -> None:
with pytest.warns(
expected_warning=UserWarning,
match=re.escape(
"""
pretty() is deprecated and will be removed in a future version.
Use OmegaConf.to_yaml. Please note that the default value for
resolve has changed to True.
dedent(
"""\
cfg.pretty() is deprecated and will be removed in a future version.
Use OmegaConf.to_yaml(cfg)
""",
)
),
):
assert c.pretty() == "foo: bar\n"
Expand Down

0 comments on commit 6e0c3d7

Please sign in to comment.