diff --git a/src/flask/app.py b/src/flask/app.py index 854a796e..3a4df366 100644 --- a/src/flask/app.py +++ b/src/flask/app.py @@ -1672,13 +1672,13 @@ class Flask(Scaffold): # a 3-tuple is unpacked directly if len_rv == 3: - rv, status, headers = rv + rv, status, headers = rv # type: ignore[misc] # decide if a 2-tuple has status or headers elif len_rv == 2: if isinstance(rv[1], (Headers, dict, tuple, list)): rv, headers = rv else: - rv, status = rv + rv, status = rv # type: ignore[misc] # other sized tuples are not allowed else: raise TypeError( @@ -1701,7 +1701,11 @@ class Flask(Scaffold): # let the response class set the status and headers instead of # waiting to do it manually, so that the class can handle any # special logic - rv = self.response_class(rv, status=status, headers=headers) + rv = self.response_class( + rv, + status=status, + headers=headers, # type: ignore[arg-type] + ) status = headers = None elif isinstance(rv, dict): rv = jsonify(rv) @@ -1729,13 +1733,13 @@ class Flask(Scaffold): # prefer the status if it was provided if status is not None: if isinstance(status, (str, bytes, bytearray)): - rv.status = status # type: ignore + rv.status = status else: rv.status_code = status # extend existing headers with provided headers if headers: - rv.headers.update(headers) + rv.headers.update(headers) # type: ignore[arg-type] return rv diff --git a/src/flask/helpers.py b/src/flask/helpers.py index 84059319..fe47500e 100644 --- a/src/flask/helpers.py +++ b/src/flask/helpers.py @@ -186,7 +186,7 @@ def make_response(*args: t.Any) -> "Response": return current_app.response_class() if len(args) == 1: args = args[0] - return current_app.make_response(args) + return current_app.make_response(args) # type: ignore def url_for(endpoint: str, **values: t.Any) -> str: diff --git a/src/flask/typing.py b/src/flask/typing.py index bd8e61dc..a839a7e4 100644 --- a/src/flask/typing.py +++ b/src/flask/typing.py @@ -4,14 +4,16 @@ import typing as t if t.TYPE_CHECKING: from _typeshed.wsgi import WSGIApplication # noqa: F401 from werkzeug.datastructures import Headers # noqa: F401 - from .wrappers import Response # noqa: F401 + from werkzeug.wrappers.response import Response # noqa: F401 # The possible types that are directly convertible or are a Response object. ResponseValue = t.Union[ "Response", - t.AnyStr, + str, + bytes, t.Dict[str, t.Any], # any jsonify-able dict - t.Generator[t.AnyStr, None, None], + t.Iterator[str], + t.Iterator[bytes], ] StatusCode = int