forked from orbit-oss/flask
don't use AnyStr for ResponseValue type
This commit is contained in:
parent
8886328822
commit
190dd4df86
3 changed files with 15 additions and 9 deletions
|
|
@ -1672,13 +1672,13 @@ class Flask(Scaffold):
|
||||||
|
|
||||||
# a 3-tuple is unpacked directly
|
# a 3-tuple is unpacked directly
|
||||||
if len_rv == 3:
|
if len_rv == 3:
|
||||||
rv, status, headers = rv
|
rv, status, headers = rv # type: ignore[misc]
|
||||||
# decide if a 2-tuple has status or headers
|
# decide if a 2-tuple has status or headers
|
||||||
elif len_rv == 2:
|
elif len_rv == 2:
|
||||||
if isinstance(rv[1], (Headers, dict, tuple, list)):
|
if isinstance(rv[1], (Headers, dict, tuple, list)):
|
||||||
rv, headers = rv
|
rv, headers = rv
|
||||||
else:
|
else:
|
||||||
rv, status = rv
|
rv, status = rv # type: ignore[misc]
|
||||||
# other sized tuples are not allowed
|
# other sized tuples are not allowed
|
||||||
else:
|
else:
|
||||||
raise TypeError(
|
raise TypeError(
|
||||||
|
|
@ -1701,7 +1701,11 @@ class Flask(Scaffold):
|
||||||
# let the response class set the status and headers instead of
|
# let the response class set the status and headers instead of
|
||||||
# waiting to do it manually, so that the class can handle any
|
# waiting to do it manually, so that the class can handle any
|
||||||
# special logic
|
# 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
|
status = headers = None
|
||||||
elif isinstance(rv, dict):
|
elif isinstance(rv, dict):
|
||||||
rv = jsonify(rv)
|
rv = jsonify(rv)
|
||||||
|
|
@ -1729,13 +1733,13 @@ class Flask(Scaffold):
|
||||||
# prefer the status if it was provided
|
# prefer the status if it was provided
|
||||||
if status is not None:
|
if status is not None:
|
||||||
if isinstance(status, (str, bytes, bytearray)):
|
if isinstance(status, (str, bytes, bytearray)):
|
||||||
rv.status = status # type: ignore
|
rv.status = status
|
||||||
else:
|
else:
|
||||||
rv.status_code = status
|
rv.status_code = status
|
||||||
|
|
||||||
# extend existing headers with provided headers
|
# extend existing headers with provided headers
|
||||||
if headers:
|
if headers:
|
||||||
rv.headers.update(headers)
|
rv.headers.update(headers) # type: ignore[arg-type]
|
||||||
|
|
||||||
return rv
|
return rv
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -186,7 +186,7 @@ def make_response(*args: t.Any) -> "Response":
|
||||||
return current_app.response_class()
|
return current_app.response_class()
|
||||||
if len(args) == 1:
|
if len(args) == 1:
|
||||||
args = args[0]
|
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:
|
def url_for(endpoint: str, **values: t.Any) -> str:
|
||||||
|
|
|
||||||
|
|
@ -4,14 +4,16 @@ import typing as t
|
||||||
if t.TYPE_CHECKING:
|
if t.TYPE_CHECKING:
|
||||||
from _typeshed.wsgi import WSGIApplication # noqa: F401
|
from _typeshed.wsgi import WSGIApplication # noqa: F401
|
||||||
from werkzeug.datastructures import Headers # 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.
|
# The possible types that are directly convertible or are a Response object.
|
||||||
ResponseValue = t.Union[
|
ResponseValue = t.Union[
|
||||||
"Response",
|
"Response",
|
||||||
t.AnyStr,
|
str,
|
||||||
|
bytes,
|
||||||
t.Dict[str, t.Any], # any jsonify-able dict
|
t.Dict[str, t.Any], # any jsonify-able dict
|
||||||
t.Generator[t.AnyStr, None, None],
|
t.Iterator[str],
|
||||||
|
t.Iterator[bytes],
|
||||||
]
|
]
|
||||||
StatusCode = int
|
StatusCode = int
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue