deprecate as_tuple
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 a2258dd · Browse files · 2 files·+41 added−12 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+41 added−12 removed
- other:+41 added−12 removed
Provenance
- Commit
564bb27- Tree
6c4240e- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
a2258dd
2 files changed+41 added−12 removed
modified:src/flask/testing.py+30 added-12 removed
7 unmodified lines8 from werkzeug.test import Client9 from werkzeug.urls import url_parse10 from werkzeug.wrappers import Request as BaseRequest11 12-from . import _request_ctx_stack12 from .cli import ScriptInfo13+from .globals import _request_ctx_stack14 from .json import dumps as json_dumps15 from .sessions import SessionMixin16 17 if t.TYPE_CHECKING:18+ from werkzeug.test import TestResponse19+20 from .app import Flask19- from .wrappers import Response21 22 23 class EnvironBuilder(werkzeug.test.EnvironBuilder):24 """An :class:`~werkzeug.test.EnvironBuilder`, that takes defaults from the146 unmodified lines171 session_interface.save_session(app, sess, resp)172 headers = resp.get_wsgi_headers(c.request.environ)173 self.cookie_jar.extract_wsgi(c.request.environ, headers)174 174- def open( # type: ignore175+ def open(176 self,177 *args: t.Any,177- as_tuple: bool = False,178 buffered: bool = False,179 follow_redirects: bool = False,180 **kwargs: t.Any,181- ) -> "Response":181+ ) -> "TestResponse":182+ as_tuple = kwargs.pop("as_tuple", None)183+184 # Same logic as super.open, but apply environ_base and preserve_context.185 request = None186 187 def copy_environ(other):26 unmodified lines214 request = builder.get_request()215 finally:216 builder.close()217 216- return super().open( # type: ignore217- request,218- as_tuple=as_tuple,219- buffered=buffered,220- follow_redirects=follow_redirects,221- )218+ if as_tuple is not None:219+ import warnings220 221+ warnings.warn(222+ "'as_tuple' is deprecated and will be removed in"223+ " Werkzeug 2.1 and Flask 2.1. Use"224+ " 'response.request.environ' instead.",225+ DeprecationWarning,226+ stacklevel=3,227+ )228+ return super().open(229+ request,230+ as_tuple=as_tuple,231+ buffered=buffered,232+ follow_redirects=follow_redirects,233+ )234+ else:235+ return super().open(236+ request,237+ buffered=buffered,238+ follow_redirects=follow_redirects,239+ )240+241 def __enter__(self) -> "FlaskClient":242 if self.preserve_context:243 raise RuntimeError("Cannot nest client invocations")244 self.preserve_context = True44 unmodified lines289 290 :return: a :class:`~click.testing.Result` object.291 """292 if cli is None:275- cli = self.app.cli293+ cli = self.app.cli # type: ignore294 295 if "obj" not in kwargs:296 kwargs["obj"] = ScriptInfo(create_app=lambda: self.app)297 1 unmodified linemodified:CHANGES.rst+11 added
1 .. currentmodule:: flask2 3+Version 2.0.34+-------------5+6+Unreleased7+8+- The test client's ``as_tuple`` parameter is deprecated and will be9+ removed in Werkzeug 2.1. It is now also deprecated in Flask, to be10+ removed in Flask 2.1, while remaining compatible with both in11+ 2.0.x. Use ``response.request.environ`` instead. :pr:`4341`12+13+14 Version 2.0.215 -------------16 17 Released 2021-10-041178 unmodified lines