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 #698
This addresses issue #821
  • Loading branch information
pixelb committed May 12, 2022
1 parent 5e6b33c commit 70f5d29
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 31 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 @@ -612,21 +612,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

# DEPRECATED: remove in 2.2
@staticmethod
def is_none(obj: Any, key: Optional[Union[int, DictKeyType]] = None) -> bool:
Expand Down
16 changes: 0 additions & 16 deletions tests/test_omegaconf.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import pathlib
import platform
import re
from pathlib import Path
from typing import Any

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 70f5d29

Please sign in to comment.