Skip to content

Commit 190dd4d

Browse files
committed
don't use AnyStr for ResponseValue type
1 parent 8886328 commit 190dd4d

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

src/flask/app.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,13 +1672,13 @@ def make_response(self, rv: ResponseReturnValue) -> Response:
16721672

16731673
# a 3-tuple is unpacked directly
16741674
if len_rv == 3:
1675-
rv, status, headers = rv
1675+
rv, status, headers = rv # type: ignore[misc]
16761676
# decide if a 2-tuple has status or headers
16771677
elif len_rv == 2:
16781678
if isinstance(rv[1], (Headers, dict, tuple, list)):
16791679
rv, headers = rv
16801680
else:
1681-
rv, status = rv
1681+
rv, status = rv # type: ignore[misc]
16821682
# other sized tuples are not allowed
16831683
else:
16841684
raise TypeError(
@@ -1701,7 +1701,11 @@ def make_response(self, rv: ResponseReturnValue) -> Response:
17011701
# let the response class set the status and headers instead of
17021702
# waiting to do it manually, so that the class can handle any
17031703
# special logic
1704-
rv = self.response_class(rv, status=status, headers=headers)
1704+
rv = self.response_class(
1705+
rv,
1706+
status=status,
1707+
headers=headers, # type: ignore[arg-type]
1708+
)
17051709
status = headers = None
17061710
elif isinstance(rv, dict):
17071711
rv = jsonify(rv)
@@ -1729,13 +1733,13 @@ def make_response(self, rv: ResponseReturnValue) -> Response:
17291733
# prefer the status if it was provided
17301734
if status is not None:
17311735
if isinstance(status, (str, bytes, bytearray)):
1732-
rv.status = status # type: ignore
1736+
rv.status = status
17331737
else:
17341738
rv.status_code = status
17351739

17361740
# extend existing headers with provided headers
17371741
if headers:
1738-
rv.headers.update(headers)
1742+
rv.headers.update(headers) # type: ignore[arg-type]
17391743

17401744
return rv
17411745

src/flask/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def index():
186186
return current_app.response_class()
187187
if len(args) == 1:
188188
args = args[0]
189-
return current_app.make_response(args)
189+
return current_app.make_response(args) # type: ignore
190190

191191

192192
def url_for(endpoint: str, **values: t.Any) -> str:

src/flask/typing.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
if t.TYPE_CHECKING:
55
from _typeshed.wsgi import WSGIApplication # noqa: F401
66
from werkzeug.datastructures import Headers # noqa: F401
7-
from .wrappers import Response # noqa: F401
7+
from werkzeug.wrappers.response import Response # noqa: F401
88

99
# The possible types that are directly convertible or are a Response object.
1010
ResponseValue = t.Union[
1111
"Response",
12-
t.AnyStr,
12+
str,
13+
bytes,
1314
t.Dict[str, t.Any], # any jsonify-able dict
14-
t.Generator[t.AnyStr, None, None],
15+
t.Iterator[str],
16+
t.Iterator[bytes],
1517
]
1618
StatusCode = int
1719

0 commit comments

Comments
 (0)