marshmallow-code / marshmallow-code/webargs

RFC: Use annotations for parsing arguments

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

Nobody has claimed this yet.

feedback welcome
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

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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.