Skip to content

fallback

openml._api.resources.base.fallback #

FallbackProxy #

FallbackProxy(*api_versions: Any)

Proxy object that provides transparent fallback across multiple API versions.

This class delegates attribute access to a sequence of API implementations. When a callable attribute is invoked and raises OpenMLNotSupportedError, the proxy automatically attempts the same method on subsequent API instances until one succeeds.

PARAMETER DESCRIPTION
*api_versions

One or more API implementation instances ordered by priority. The first API is treated as the primary implementation, and subsequent APIs are used as fallbacks.

TYPE: Any DEFAULT: ()

RAISES DESCRIPTION
ValueError

If no API implementations are provided.

Notes

Attribute lookup is performed dynamically via __getattr__. Only methods that raise OpenMLNotSupportedError trigger fallback behavior. Other exceptions are propagated immediately.

Source code in openml/_api/resources/base/fallback.py
def __init__(self, *api_versions: Any):
    if not api_versions:
        raise ValueError("At least one API version must be provided")
    self._apis = api_versions

__getattr__ #

__getattr__(name: str) -> Any

Dynamically resolve attribute access across API implementations.

PARAMETER DESCRIPTION
name

Name of the attribute being accessed.

TYPE: str

RETURNS DESCRIPTION
Any

The resolved attribute. If it is callable, a wrapped function providing fallback behavior is returned.

RAISES DESCRIPTION
AttributeError

If none of the API implementations define the attribute.

Source code in openml/_api/resources/base/fallback.py
def __getattr__(self, name: str) -> Any:
    """
    Dynamically resolve attribute access across API implementations.

    Parameters
    ----------
    name : str
        Name of the attribute being accessed.

    Returns
    -------
    Any
        The resolved attribute. If it is callable, a wrapped function
        providing fallback behavior is returned.

    Raises
    ------
    AttributeError
        If none of the API implementations define the attribute.
    """
    api, attr = self._find_attr(name)
    if callable(attr):
        return self._wrap_callable(name, api, attr)
    return attr