Skip to content

resolve_context

faststream.utils.context.types.resolve_context #

resolve_context(argument: str) -> Any

Resolve the context of an argument.

PARAMETER DESCRIPTION
argument

A string representing the argument.

TYPE: str

RETURNS DESCRIPTION
Any

The resolved context of the argument.

RAISES DESCRIPTION
AttributeError

If the attribute does not exist in the context.

Note

The above docstring is autogenerated by docstring-gen library (https://docstring-gen.airt.ai)

Source code in faststream/utils/context/types.py
def resolve_context(argument: str) -> Any:
    """Resolve the context of an argument.

    Args:
        argument: A string representing the argument.

    Returns:
        The resolved context of the argument.

    Raises:
        AttributeError: If the attribute does not exist in the context.
    !!! note

        The above docstring is autogenerated by docstring-gen library (https://docstring-gen.airt.ai)
    """
    keys = argument.split(".")

    v = context.context[keys[0]]
    for i in keys[1:]:
        if isinstance(v, Mapping):
            v = v[i]
        else:
            v = getattr(v, i)

    return v

Last update: 2023-11-13