Skip to content

Attribute access

Small, shared boundary for configuration-driven attribute access.

Objects expose normal attributes and may also store extensible values in a properties dictionary. Nested access checks that dictionary at each step; flat access checks the root dictionary for the complete path first.

get_attribute(obj, path, default=None, *, nested_properties=True)

Read an attribute, property, dictionary key, or dotted path.

Source code in may/utils/attribute_access.py
88
89
90
91
92
93
94
95
96
97
98
99
def get_attribute(
    obj: Any,
    path: Optional[str],
    default: Any = None,
    *,
    nested_properties: bool = True,
) -> Any:
    """Read an attribute, property, dictionary key, or dotted path."""
    if obj is None or not path:
        return default
    value = _resolve_attribute(path, nested_properties)(obj)
    return default if value is _MISSING else value