python-attrs / python-attrs/cattrs

How to hook into structuring of a simple dict?

Open
#524 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

more-info-needed
Dominant language
Python
Stars
1.1k
Forks
159
Avg merge
12h 21m
Merged PRs (30d)
6

Description

  • 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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No file, test, or entry point is named in the report. Start by reviewing cattrs' structuring and converter-hook documentation and the existing recursive structuring behavior; done means identifying a supported hook path for datetime strings inside dicts without creating recursion loops.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.