Skip to content

Commit

Permalink
remove support for OmegaConf.is_optional()
Browse files Browse the repository at this point in the history
Was slated for removal in 2.2

The deprecation was handled in issue omry#698
This addresses issue omry#821
  • Loading branch information
pixelb committed May 13, 2022
1 parent 730c9d7 commit 6097e85
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 32 deletions.
1 change: 1 addition & 0 deletions news/698.api_change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Removed support for `OmegaConf.is_optional()`.
15 changes: 0 additions & 15 deletions omegaconf/omegaconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,21 +594,6 @@ def is_missing(cfg: Any, key: DictKeyType) -> bool:
except (UnsupportedInterpolationType, KeyError, AttributeError):
return False

# DEPRECATED: remove in 2.2
@staticmethod
def is_optional(obj: Any, key: Optional[Union[int, str]] = None) -> bool:
warnings.warn(
"`OmegaConf.is_optional()` is deprecated, see https://github.com/omry/omegaconf/issues/698",
stacklevel=2,
)
if key is not None:
assert isinstance(obj, Container)
obj = obj._get_node(key)
if isinstance(obj, Node):
return obj._is_optional()
else:
return True

@staticmethod
def is_interpolation(node: Any, key: Optional[Union[int, str]] = None) -> bool:
if key is not None:
Expand Down
18 changes: 1 addition & 17 deletions tests/test_omegaconf.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import pathlib
import platform
import re
from pathlib import Path
from typing import Any

from pytest import mark, param, raises, warns
from pytest import mark, param, raises

from omegaconf import (
MISSING,
Expand Down Expand Up @@ -227,21 +226,6 @@ def test_is_dict(cfg: Any, expected: bool) -> None:
assert OmegaConf.is_dict(cfg) == expected


def test_is_optional_deprecation() -> None:
with warns(UserWarning, match=re.escape("`OmegaConf.is_optional()` is deprecated")):
OmegaConf.is_optional("xxx")


def test_coverage_for_deprecated_OmegaConf_is_optional() -> None:
cfg = OmegaConf.create({"node": 123})
with warns(UserWarning):
assert OmegaConf.is_optional(cfg)
with warns(UserWarning):
assert OmegaConf.is_optional(cfg, "node")
with warns(UserWarning):
assert OmegaConf.is_optional("not_a_node")


@mark.parametrize("is_none", [True, False])
@mark.parametrize(
"fac",
Expand Down

0 comments on commit 6097e85

Please sign in to comment.