From a56b445511227297eafff1677d924dd7d2a9e404 Mon Sep 17 00:00:00 2001 From: Miles Olson Date: Thu, 31 Oct 2024 09:06:40 -0700 Subject: [PATCH] Delete not_none Summary: As titled Reviewed By: saitcakmak, Balandat, paschai Differential Revision: D65278088 --- ax/modelbridge/generation_strategy.py | 2 +- ax/utils/common/tests/test_typeutils.py | 6 ------ ax/utils/common/typeutils.py | 17 ----------------- 3 files changed, 1 insertion(+), 24 deletions(-) diff --git a/ax/modelbridge/generation_strategy.py b/ax/modelbridge/generation_strategy.py index ffaa9428b43..81aa8fc4079 100644 --- a/ax/modelbridge/generation_strategy.py +++ b/ax/modelbridge/generation_strategy.py @@ -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__) diff --git a/ax/utils/common/tests/test_typeutils.py b/ax/utils/common/tests/test_typeutils.py index d03775709ad..506c34f5e08 100644 --- a/ax/utils/common/tests/test_typeutils.py +++ b/ax/utils/common/tests/test_typeutils.py @@ -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): diff --git a/ax/utils/common/typeutils.py b/ax/utils/common/typeutils.py index bd3377fb015..11f36818326 100644 --- a/ax/utils/common/typeutils.py +++ b/ax/utils/common/typeutils.py @@ -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).