Skip to content
This repository was archived by the owner on Feb 2, 2019. It is now read-only.
This repository was archived by the owner on Feb 2, 2019. It is now read-only.

Pulling a list of dicts from AttrDict results in just a list of dicts. #47

@nicholishen

Description

@nicholishen

As the title states, just a list of regular dicts instead of AttrDicts. Here is a workaround.

def deep_attrdict(d: dict) -> AttrDict:
    """Uses recursion to dive deep into the dict
    and convert all dict types to type AttrDict. This will 
    eliminate the bug where pulling a list of dicts 
    out of an AttrDict results in just a list of dicts.
    """
    d = AttrDict(d)
    for k, v in d.items():
        if isinstance(v, dict):
            d[k] = deep_attrdict(v)
        elif isinstance(v, list):
            for i, item in enumerate(v):
                if isinstance(item, dict):
                    v[i] = deep_attrdict(item)
    return d

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions