Skip to content
Myr

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

2 files+41 added−12 removed

modified:src/flask/testing.py+30 added-12 removed
7 unmodified lines
8from werkzeug.test import Client9from werkzeug.urls import url_parse10from werkzeug.wrappers import Request as BaseRequest1112from . import _request_ctx_stack12from .cli import ScriptInfo13from .globals import _request_ctx_stack14from .json import dumps as json_dumps15from .sessions import SessionMixin1617if t.TYPE_CHECKING:18 from werkzeug.test import TestResponse1920 from .app import Flask19 from .wrappers import Response212223class EnvironBuilder(werkzeug.test.EnvironBuilder):24 """An :class:`~werkzeug.test.EnvironBuilder`, that takes defaults from the
146 unmodified lines
171 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)174174 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)183184 # Same logic as super.open, but apply environ_base and preserve_context.185 request = None186187 def copy_environ(other):
26 unmodified lines
214 request = builder.get_request()215 finally:216 builder.close()217216 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 warnings220221 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 )240241 def __enter__(self) -> "FlaskClient":242 if self.preserve_context:243 raise RuntimeError("Cannot nest client invocations")244 self.preserve_context = True
44 unmodified lines
289290 :return: a :class:`~click.testing.Result` object.291 """292 if cli is None:275 cli = self.app.cli293 cli = self.app.cli # type: ignore294295 if "obj" not in kwargs:296 kwargs["obj"] = ScriptInfo(create_app=lambda: self.app)297
1 unmodified line
modified:CHANGES.rst+11 added
1.. currentmodule:: flask23Version 2.0.34-------------56Unreleased78- 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`121314Version 2.0.215-------------1617Released 2021-10-04
1178 unmodified lines