Skip to content

Feature Request: Use dedicated (un)structure methods if available #394

@pohlt

Description

@pohlt

To (uns)structure certain objects, cattrs allows to register (un)structure hooks. This is a great way to allow (un)structuring of any object, in particular if I cannot modify the underlying classes.

If I have control over the classes, it could be easier to define a (un)structure function or property within the class itself, because this code would reside within each class. During (un)structuring, cattrs could look for the availability of such functions and use the accordingly.

One way to implement that would be to tell the converter to look for a certain method/property (_structure in the example below):

converter.register_structure_property("_structure")

What to you think?

BTW: Thanks a lot for cattrs. I love it!

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