simplebench.type_proxies.session_type_proxy module🔗

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

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

The SessionTypeProxy class acts as a stand-in for the actual Session type.

class simplebench.type_proxies.session_type_proxy.SessionTypeProxy[source]🔗

Bases: LazyTypeProxy[Session]

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

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

Warning

Do not attempt to import Session 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 Session class instead if an actual Session instance is needed.

simplebench.type_proxies.session_type_proxy.is_session(obj: object) TypeGuard[Session][source]🔗

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

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

Usage:

if is_session(some_object):
    # Now `some_object` is treated as a `Session` instance by static type checkers.