Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Remove deprecated BaseContainer.{pretty,select,update_node} #672

Merged
merged 1 commit into from
Apr 8, 2021
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
1 change: 1 addition & 0 deletions news/671.api_change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove BaseContainer.{pretty,select,update_node} that have been deprecated since OmegaConf 2.0.
12 changes: 0 additions & 12 deletions omegaconf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,18 +298,6 @@ class Container(Node):

_metadata: ContainerMetadata

@abstractmethod
def pretty(self, resolve: bool = False, sort_keys: bool = False) -> str:
...

@abstractmethod
def update_node(self, key: str, value: Any = None) -> None:
...

@abstractmethod
def select(self, key: str, throw_on_missing: bool = False) -> Any:
...

def _get_node(
self,
key: Any,
Expand Down
39 changes: 0 additions & 39 deletions omegaconf/basecontainer.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import copy
import sys
import warnings
from abc import ABC, abstractmethod
from enum import Enum
from textwrap import dedent
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple, Union

import yaml
Expand Down Expand Up @@ -156,28 +154,6 @@ def fail() -> None:

OmegaConf.update(self, key, value, merge=True)

def select(self, key: str, throw_on_missing: bool = False) -> Any:
from omegaconf import OmegaConf

warnings.warn(
"select() is deprecated, use OmegaConf.select(). (Since 2.0)",
category=UserWarning,
stacklevel=2,
)

return OmegaConf.select(self, key, throw_on_missing=throw_on_missing)

def update_node(self, key: str, value: Any = None) -> None:
from omegaconf import OmegaConf

warnings.warn(
"update_node() is deprecated, use OmegaConf.update(). (Since 2.0)",
category=UserWarning,
stacklevel=2,
)

OmegaConf.update(self, key, value, merge=False)

def is_empty(self) -> bool:
"""return true if config is empty"""
return len(self.__dict__["_content"]) == 0
Expand Down Expand Up @@ -261,21 +237,6 @@ def convert(val: Node) -> Any:

assert False

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)
"""
),
category=UserWarning,
)

return OmegaConf.to_yaml(self, resolve=resolve, sort_keys=sort_keys)

@staticmethod
def _map_merge(dest: "BaseContainer", src: "BaseContainer") -> None:
"""merge src into dest and return a new copy, does not modified input"""
Expand Down
13 changes: 1 addition & 12 deletions tests/test_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Any, Optional

from _pytest.python_api import RaisesContext
from pytest import mark, param, raises, warns
from pytest import mark, param, raises

from omegaconf import MissingMandatoryValue, OmegaConf
from omegaconf._utils import _ensure_container
Expand Down Expand Up @@ -182,17 +182,6 @@ def test_select_from_dict(self, struct: Optional[bool]) -> None:
assert OmegaConf.select(cfg, "missing", throw_on_missing=False) is None
assert OmegaConf.select(cfg, "missing") is None

def test_select_deprecated(self, struct: Optional[bool]) -> None:
cfg = OmegaConf.create({"foo": "bar"})
OmegaConf.set_struct(cfg, struct)
with warns(
expected_warning=UserWarning,
match=re.escape(
"select() is deprecated, use OmegaConf.select(). (Since 2.0)"
),
):
cfg.select("foo")


@mark.parametrize(
"cfg,key,expected",
Expand Down
19 changes: 1 addition & 18 deletions tests/test_to_yaml.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import re
from textwrap import dedent
from typing import Any

from pytest import mark, warns
from pytest import mark

from omegaconf import DictConfig, EnumNode, ListConfig, OmegaConf, _utils
from tests import Enum1, User
Expand Down Expand Up @@ -136,22 +135,6 @@ def test_to_yaml_with_enum_key() -> None:
assert s == expected


def test_pretty_deprecated() -> None:
c = OmegaConf.create({"foo": "bar"})
with warns(
expected_warning=UserWarning,
match=re.escape(
dedent(
"""\
cfg.pretty() is deprecated and will be removed in a future version.
Use OmegaConf.to_yaml(cfg)
""",
)
),
):
assert c.pretty() == "foo: bar\n"


@mark.parametrize(
"user",
[
Expand Down
12 changes: 0 additions & 12 deletions tests/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,18 +164,6 @@ def test_update_list_make_dict() -> None:
assert c == [{"a": {"a": "aa", "b": "ab"}}, {"b": {"a": "ba", "b": "bb"}}]


def test_update_node_deprecated() -> None:
c = OmegaConf.create()
with warns(
expected_warning=UserWarning,
match=re.escape(
"update_node() is deprecated, use OmegaConf.update(). (Since 2.0)"
),
):
c.update_node("foo", "bar")
assert c.foo == "bar"


def test_update_list_index_error() -> None:
c = OmegaConf.create([1, 2, 3])
assert isinstance(c, ListConfig)
Expand Down