marshmallow-code / marshmallow-code/webargs
RFC: Use annotations for parsing arguments
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.4k
- Forks
- 167
- Avg merge
- 17h 8m
- Merged PRs (30d)
- 4
Description
Add a decorator that will parse request arguments from the view function's type annotations.
I've built a working proof of concept of this idea in [webargs-starlette](https://github.com/sloria/webargs-starlette).
```python
@app.route("/")
@use_annotations(locations=("query",))
async def index(request, name: str = "World"):
return JSONResponse({"Hello": name})
```
A marshmallow `Schema` is generated from the annotations using `Schema.TYPE_MAPPING` to construct fields.
The code for `use_annotations` mostly isn't tied to Starlette and could be adapted for `AsyncParser` (and `core.Parser` when we drop Python 2 support).
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 by reviewing the proof of concept in webargs-starlette, then inspect AsyncParser and core.Parser and how marshmallow Schema.TYPE_MAPPING constructs fields. Done means adapting the annotation-based use_annotations approach for the relevant parsers so request arguments are parsed from view-function annotations.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 28/100