Skip to content

Commit

Permalink
Delete not_none
Browse files Browse the repository at this point in the history
Summary: 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 9eeec96 commit a56b445
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 24 deletions.
2 changes: 1 addition & 1 deletion ax/modelbridge/generation_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from ax.modelbridge.model_spec import FactoryFunctionModelSpec
from ax.modelbridge.transition_criterion import TrialBasedCriterion
from ax.utils.common.logger import _round_floats_for_logging, get_logger
from ax.utils.common.typeutils import checked_cast_list, not_none
from ax.utils.common.typeutils import checked_cast_list
from pyre_extensions import none_throws

logger: Logger = get_logger(__name__)
Expand Down
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 a56b445

Please sign in to comment.