Should `quart.make_response` be typed as returning `Response`?
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 45/100
Research direction
Start at the quart.make_response entry point and inspect its return typing against the reported mypy error and Flask's behavior. Done means the provided Quart example type-checks with a Response return annotation without requiring ResponseTypes; verify the change with the repository's relevant typing tests if available.
Written by the indexing model from the issue text.
Description
Steps to reproduce
With the following Quart app:
from quart import Response, make_response
from quart_trio import QuartTrio
app = QuartTrio(__name__)
@app.route("/")
async def hello_world() -> Response:
return await make_response("<p>Hello, World!</p>")
if __name__ == "__main__":
app.run()
mypy fails because make_response does not return a Response:
quart_app.py:9: error: Incompatible return value type (got "quart.wrappers.response.Response | werkzeug.wrappers.response.Response", expected "quart.wrappers.response.Response") [return-value]
Expected result
I would expect validation to pass. Indeed, the equivalent Flask app passes validation:
from flask import Flask, Response, make_response
app = Flask(__name__)
@app.route("/")
def hello_world() -> Response:
return make_response("<p>Hello, World!</p>")
Workarounds
- Use
return "<p>Hello, World!</p>"and mark the return type asstr. But figuring out the right type is tiring, is a maintenance burden and arguably introduces unnecessary variation in the code. - Use
return quart.Response("<p>Hello, World!</p>")but it quickly breaks for more complex types. I spent a lot of time trying to understand whyquart.Response({"headers": "foo", "params': "bar"})was returning "headersparams"! - Type the return as
quart.typing. ResponseTypes. This is what I'm doing right now in the urllib3 tests (https://github.com/urllib3/urllib3/pull/3193) but I would rather useResponse.
Environment
- Python version: 3.12.0
- Quart version: 0.19.3 (quart-trio 0.11.0)
- Dominant language
- Python
- Stars
- 3.7k
- Forks
- 206
- PR merge metrics
- No merged PRs in 30d
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.
More from pallets/quart
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
Difficulty 1/5 Under an hour Newbie friendliness 68/100
-
Difficulty 3/5 1-2 days Newbie friendliness 42/100
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
anthropics/skills#1811 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
speaches-ai/speaches#678 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
datalayer/mcp-compose#42 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
conda-forge/spacy-feedstock#177 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
UKGovernmentBEIS/inspect_evals#2523 ·