Skip to content

How to flatten objects with attribute-style access? #429

@tokarenko

Description

@tokarenko

Please adivse how to flatten objects with attribute-style access?
Documentation says that name_mapping map supports dictionary-style access.
For example, I would like to map nested_attr of Nested in Source to the same of Flat object:

@dataclass
class Nested:
    nested_attr: str

@dataclass
class Source:
    container: dict[str, Nested]

@dataclass
class Flat:
    nested_attr: str

retort = ConversionRetort(
            recipe=[
                name_mapping(
                    Flat,
                    map = {
                        "nested_attr": ["container", "nested_key", "nested_attr"],
                    }
                ),
            ],
        )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions