python-attrs / python-attrs/cattrs
How to hook into structuring of a simple dict?
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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