Skip to content

How to hook into structuring of a simple dict? #524

Open
@kkg-else42

Description

@kkg-else42
  • cattrs version: 23.2.3
  • Python version: 3.11
  • Operating System: Windows (dev)/Linux (prod)

Hey there!

I have a few attrs classes. Some are members of a (tagged) union, together with dict.
The unstructure already works. Among other things, datetime objects are converted into strings -- in a special format (_TIMESTAMP_FORMAT: Final[str] = '%Y%m%d_%H%M%S').

The structuring of datetime attributes in attrs instances works perfectly.
My problem is with the structuring of simple dict objects.
I need to hook into it to convert the strings (which are in that special format) into datetime objects.
But since the simple dict objects can also contain attrs instances, it must be possible to call the structuring recursively again.

I just need a hint how to call the structuring without creating an endless loop.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions