Source code for openstef_core.utils.invariants
# SPDX-FileCopyrightText: 2025 Contributors to the OpenSTEF project <openstef@lfenergy.org>
#
# SPDX-License-Identifier: MPL-2.0
"""Runtime invariant checking utilities.
Provides helper functions for asserting runtime invariants and contracts,
particularly for checking nullable values and other preconditions.
"""
[docs]
def not_none[T](value: T | None) -> T:
"""Assert that a value is not None.
Args:
value: The value to check.
Returns:
The value if it is not None.
Raises:
ValueError: If the value is None.
"""
if value is None:
raise ValueError("Expected value to be not None")
return value
__all__ = [
"not_none",
]