don't use AnyStr for ResponseValue type
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Lord · committed by David Lord · parent 8886328 · Browse files · 3 files·+15 added−9 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+15 added−9 removed
- other:+15 added−9 removed
Provenance
- Commit
190dd4d- Tree
2c5e5d4- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
8886328
3 files changed+15 added−9 removed
modified:src/flask/app.py+9 added-5 removed
1670 unmodified lines1671 len_rv = len(rv)1672 1673 # a 3-tuple is unpacked directly1674 if len_rv == 3:1675- rv, status, headers = rv1675+ rv, status, headers = rv # type: ignore[misc]1676 # decide if a 2-tuple has status or headers1677 elif len_rv == 2:1678 if isinstance(rv[1], (Headers, dict, tuple, list)):1679 rv, headers = rv1680 else:1681- rv, status = rv1681+ rv, status = rv # type: ignore[misc]1682 # other sized tuples are not allowed1683 else:1684 raise TypeError(1685 "The view function did not return a valid response tuple."14 unmodified lines1700 if isinstance(rv, (str, bytes, bytearray)):1701 # let the response class set the status and headers instead of1702 # waiting to do it manually, so that the class can handle any1703 # special logic1704- 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+ )1709 status = headers = None1710 elif isinstance(rv, dict):1711 rv = jsonify(rv)1712 elif isinstance(rv, BaseResponse) or callable(rv):19 unmodified lines1732 rv = t.cast(Response, rv)1733 # prefer the status if it was provided1734 if status is not None:1735 if isinstance(status, (str, bytes, bytearray)):1732- rv.status = status # type: ignore1736+ rv.status = status1737 else:1738 rv.status_code = status1739 1740 # extend existing headers with provided headers1741 if headers:1738- rv.headers.update(headers)1742+ rv.headers.update(headers) # type: ignore[arg-type]1743 1744 return rv1745 1746 def create_url_adapter(340 unmodified linesmodified:src/flask/helpers.py+1 added-1 removed
184 unmodified lines185 if not args:186 return current_app.response_class()187 if len(args) == 1:188 args = args[0]189- return current_app.make_response(args)189+ return current_app.make_response(args) # type: ignore190 191 192 def url_for(endpoint: str, **values: t.Any) -> str:193 """Generates a URL to the given endpoint with the method provided.597 unmodified linesmodified:src/flask/typing.py+5 added-3 removed
2 unmodified lines3 4 if t.TYPE_CHECKING:5 from _typeshed.wsgi import WSGIApplication # noqa: F4016 from werkzeug.datastructures import Headers # noqa: F4017- from .wrappers import Response # noqa: F4017+ from werkzeug.wrappers.response import Response # noqa: F4018 9 # The possible types that are directly convertible or are a Response object.10 ResponseValue = t.Union[11 "Response",12- t.AnyStr,12+ str,13+ bytes,14 t.Dict[str, t.Any], # any jsonify-able dict14- t.Generator[t.AnyStr, None, None],15+ t.Iterator[str],16+ t.Iterator[bytes],17 ]18 StatusCode = int19 20 # the possible types for an individual HTTP header35 unmodified lines