Skip to content

misc_utils

Miscellaneous utility functions that support operations performed by other modules in the okcourse library.

Functions:

Name Description
extract_literal_values_from_member

Extracts the Literal values of a specified member in a class or TypedDict.

extract_literal_values_from_type

Unwraps a Literal or any nested Union containing literals and returns the Literal values.

extract_literal_values_from_member

extract_literal_values_from_member(
    cls: Any, member: str
) -> list[Any]

Extracts the Literal values of a specified member in a class or TypedDict.

If the member's type is a Literal or contains literals within a Union like Optional[Literal[...]], the function extracts and returns all the Literal values.

An example use case for this function is to extract a list of the available models from an OpenAI library type.

extract_literal_values_from_type

extract_literal_values_from_type(typ: object) -> list[str]

Unwraps a Literal or any nested Union containing literals and returns the Literal values.

An example use case for this function is to extract a list of the available voices from an OpenAI library type.