simplebench.type_proxies.choice_type_proxy module🔗

A mechanism to create a lazy type proxy for the Choice type for runtime checks.

It allows for deferred imports and avoids circular dependencies while still enabling runtime type checks and static type checking.

The ChoiceTypeProxy class acts as a stand-in for the actual Choice type.

class simplebench.type_proxies.choice_type_proxy.ChoiceTypeProxy[source]🔗

Bases: LazyTypeProxy[Choice]

A special proxy class that acts like the Choice type for runtime checks.

It uses lazy loading to avoid circular import issues while still allowing runtime type checks and static type checking.

It can be used in isinstance and issubclass checks as if it were the actual Choice type.

Warning

Do not attempt to import Choice directly from this module, as it will lead to circular import issues and will not work as intended.

It is not intended to be instantiated directly; use the actual Choice class instead if an actual Choice instance is needed.

simplebench.type_proxies.choice_type_proxy.is_choice(obj: object) TypeGuard[Choice][source]🔗

A type-guard function that checks if an object is an instance of Choice.

This function uses the ChoiceTypeProxy to perform the check, allowing for deferred imports and avoiding circular dependencies. It has the same effect as isinstance(obj, Choice) but is safe to use without causing import issues. It also works seamlessly with static type checkers and IDEs.

Usage:

if is_choice(some_object):
    # Now `some_object` is treated as a `Choice` instance by static type checkers.
Parameters:

obj (object) – The object to check.

Returns:

True if the object is an instance of Choice, False otherwise

Return type:

TypeGuard[Choice]