radioviz.services.typing_helpers

Typing helper service module for radioviz application.

This module provides utility functions for handling optional variables in a statically typed environment. It offers options for runtime checks and static analysis assumptions to simplify code that deals with variables guaranteed to be initialized at runtime but defined as Optional[T] for various reasons.

Module Attributes

T

Generic type variable for typing helpers.

Functions

assume_not_none(value)

Assume that a value is not None for static typing purposes and return it with non-Optional type.

require_not_none(value[, name])

Ensure that a value is not None at runtime and return it with non-Optional type.

class radioviz.services.typing_helpers.T

Generic type variable for typing helpers.

alias of TypeVar(‘T’)

radioviz.services.typing_helpers.assume_not_none(value: T | None) T[source]

Assume that a value is not None for static typing purposes and return it with non-Optional type.

This function performs an assertion within a TYPE_CHECKING block to satisfy the static type checker without introducing runtime overhead. Use this function when you are certain the value is initialized but want to avoid runtime checks.

Parameters:

value (Optional[T]) – The value to assume is not None.

Returns:

The value as type T, assumed to be not None.

Return type:

T

radioviz.services.typing_helpers.require_not_none(value: T | None, name: str = 'Variable') T[source]

Ensure that a value is not None at runtime and return it with non-Optional type.

Parameters:
  • value (Optional[T]) – The value to check for being not None.

  • name (str) – The name of the variable to use in the error message if it’s None.

Returns:

The value as type T, guaranteed to be not None.

Return type:

T

Raises:

RuntimeError – If the value is None.