python-attrs / python-attrs/cattrs
How to deserialize multidict to data model?
Open
Nobody has claimed this yet.
question
- Dominant language
- Python
- Stars
- 1.1k
- Forks
- 159
- Avg merge
- 12h 21m
- Merged PRs (30d)
- 6
Description
multidict: https://github.com/aio-libs/multidict
import dataclasses
import typing
import cattrs
import multidict
@dataclasses.dataclass
class Model:
a: typing.List[str]
b: str
d = multidict.MultiDict([('a', '111'), ('b', '2'), ('a', '333')])
obj = cattrs.structure(d, Model)
print(obj)
d = multidict.MultiDict([('a', '111'), ('b', '2')])
obj = cattrs.structure(d, Model)
print(obj)
want:
Model(a=['111', '333'], b='222')
Model(a=['111'], b='222')
actual:
Model(a=['1', '1', '1'], b='222')
Model(a=['1', '1', '1'], b='222')
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
Start with the Python reproduction in issue #407 and inspect cattrs's structuring path for multidict mappings and list-typed dataclass fields. Done means repeated keys produce all values in Model.a, a single key produces a one-item list, and the scalar b value remains correct; add or run a regression test if the repository provides a relevant test location.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100