don't use AnyStr for ResponseValue type

This commit is contained in:
David Lord 2022-03-15 07:36:21 -07:00
parent 8886328822
commit 190dd4df86
No known key found for this signature in database
GPG key ID: 7A1C87E3F5BC42A8
3 changed files with 15 additions and 9 deletions

View file

@ -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