Skip to content

Commit

Permalink
Delete not_none (facebook#3003)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#3003

As titled

Reviewed By: saitcakmak, Balandat, paschai

Differential Revision: D65278088
  • Loading branch information
mpolson64 authored and facebook-github-bot committed Oct 31, 2024
1 parent 0f8db2a commit 163967e
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 23 deletions.
6 changes: 0 additions & 6 deletions ax/utils/common/tests/test_typeutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,11 @@
checked_cast_dict,
checked_cast_list,
checked_cast_optional,
not_none,
)
from ax.utils.common.typeutils_nonnative import numpy_type_to_python_type


class TestTypeUtils(TestCase):
def test_not_none(self) -> None:
self.assertEqual(not_none("not_none"), "not_none")
with self.assertRaises(ValueError):
not_none(None)

def test_checked_cast(self) -> None:
self.assertEqual(checked_cast(float, 2.0), 2.0)
with self.assertRaises(ValueError):
Expand Down
17 changes: 0 additions & 17 deletions ax/utils/common/typeutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,6 @@
Y = TypeVar("Y")


def not_none(val: T | None, message: str | None = None) -> T:
"""
Unbox an optional type.
Args:
val: the value to cast to a non ``None`` type
message: optional override of the default error message
Returns:
V: ``val`` when ``val`` is not ``None``
Throws:
ValueError if ``val`` is ``None``
"""
if val is None:
raise ValueError(message or "Argument to `not_none` was None.")
return val


def checked_cast(typ: type[T], val: V, exception: Exception | None = None) -> T:
"""
Cast a value to a type (with a runtime safety check).
Expand Down

0 comments on commit 163967e

Please sign in to comment.