Merge branch '2.2.x'
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 · parents cc66213, 618fdc8 · Browse files · 13 files·+86 added−93 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
13 files+86 added−93 removed
- tests:+2 added−2 removed
- other:+84 added−91 removed
Provenance
- Commit
066a35d- Tree
fd6ceaa- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent 1
cc66213- Parent 2
618fdc8
13 files changed+86 added−93 removed
modified:docs/api.rst+45 added-45 removed
1 unmodified line2 ===3 4 .. module:: flask5 6-This part of the documentation covers all the interfaces of Flask. For6+This part of the documentation covers all the interfaces of Flask. For7 parts where Flask depends on external libraries, we document the most8 important right here and provide links to the canonical documentation.9 10 22 unmodified lines33 34 .. attribute:: request35 36 To access incoming request data, you can use the global `request`37- object. Flask parses incoming request data for you and gives you38- access to it through that global object. Internally Flask makes37+ object. Flask parses incoming request data for you and gives you38+ access to it through that global object. Internally Flask makes39 sure that you always get the correct data for the active thread if you40 are in a multithreaded environment.41 42- This is a proxy. See :ref:`notes-on-proxies` for more information.42+ This is a proxy. See :ref:`notes-on-proxies` for more information.43 44 The request object is an instance of a :class:`~flask.Request`.45 46 21 unmodified lines68 69 The session object works pretty much like an ordinary dict, with the70 difference that it keeps track of modifications.71 72- This is a proxy. See :ref:`notes-on-proxies` for more information.72+ This is a proxy. See :ref:`notes-on-proxies` for more information.73 74 The following attributes are interesting:75 76 .. attribute:: new1 unmodified line78 ``True`` if the session is new, ``False`` otherwise.79 80 .. attribute:: modified81 82- ``True`` if the session object detected a modification. Be advised82+ ``True`` if the session object detected a modification. Be advised83 that modifications on mutable structures are not picked up84 automatically, in that situation you have to explicitly set the85- attribute to ``True`` yourself. Here an example::85+ attribute to ``True`` yourself. Here an example::86 87 # this change is not picked up because a mutable object (here88 # a list) is changed.89 session['objects'].append(42)2 unmodified lines92 93 .. attribute:: permanent94 95 If set to ``True`` the session lives for96- :attr:`~flask.Flask.permanent_session_lifetime` seconds. The97- default is 31 days. If set to ``False`` (which is the default) the96+ :attr:`~flask.Flask.permanent_session_lifetime` seconds. The97+ default is 31 days. If set to ``False`` (which is the default) the98 session will be deleted when the user closes the browser.99 100 101 Session Interface52 unmodified lines154 .. currentmodule:: flask155 156 To share data that is valid for one request only from one function to157 another, a global variable is not good enough because it would break in158-threaded environments. Flask provides you with a special object that158+threaded environments. Flask provides you with a special object that159 ensures it is only valid for the active request and that will return160-different values for each request. In a nutshell: it does the right160+different values for each request. In a nutshell: it does the right161 thing, like it does for :class:`request` and :class:`session`.162 163 .. data:: g164 181 unmodified lines346 .. versionadded:: 0.6347 348 .. data:: signals.signals_available349 350- ``True`` if the signaling system is available. This is the case350+ ``True`` if the signaling system is available. This is the case351 when `blinker`_ is installed.352 353 The following signals exist in Flask:354 355 .. data:: template_rendered356 357- This signal is sent when a template was successfully rendered. The357+ This signal is sent when a template was successfully rendered. The358 signal is invoked with the instance of the template as `template`359 and the context as dictionary (named `context`).360 361 Example subscriber::25 unmodified lines387 388 .. data:: request_started389 390 This signal is sent when the request context is set up, before391- any request processing happens. Because the request context is already391+ any request processing happens. Because the request context is already392 bound, the subscriber can access the request with the standard global393 proxies such as :class:`~flask.request`.394 395 Example subscriber::11 unmodified lines407 408 Example subscriber::409 410 def log_response(sender, response, **extra):411- sender.logger.debug('Request context is about to close down. '411+ sender.logger.debug('Request context is about to close down. '412 'Response: %s', response)413 414 from flask import request_finished415 request_finished.connect(log_response, app)28 unmodified lines444 got_request_exception.connect(log_security_exception, app)445 446 .. data:: request_tearing_down447 448- This signal is sent when the request is tearing down. This is always449- called, even if an exception is caused. Currently functions listening448+ This signal is sent when the request is tearing down. This is always449+ called, even if an exception is caused. Currently functions listening450 to this signal are called after the regular teardown handlers, but this451 is not something you can rely on.452 453 Example subscriber::9 unmodified lines463 there was one.464 465 .. data:: appcontext_tearing_down466 467- This signal is sent when the app context is tearing down. This is always468- called, even if an exception is caused. Currently functions listening467+ This signal is sent when the app context is tearing down. This is always468+ called, even if an exception is caused. Currently functions listening469 to this signal are called after the regular teardown handlers, but this470 is not something you can rely on.471 472 Example subscriber::8 unmodified lines481 to the exception that caused the teardown if there was one.482 483 .. data:: appcontext_pushed484 485- This signal is sent when an application context is pushed. The sender486- is the application. This is usually useful for unittests in order to487- temporarily hook in information. For instance it can be used to485+ This signal is sent when an application context is pushed. The sender486+ is the application. This is usually useful for unittests in order to487+ temporarily hook in information. For instance it can be used to488 set a resource early onto the `g` object.489 490 Example usage::491 18 unmodified lines510 .. versionadded:: 0.10511 512 .. data:: appcontext_popped513 514- This signal is sent when an application context is popped. The sender515- is the application. This usually falls in line with the514+ This signal is sent when an application context is popped. The sender515+ is the application. This usually falls in line with the516 :data:`appcontext_tearing_down` signal.517 518 .. versionadded:: 0.10519 520 521 .. data:: message_flashed522 523- This signal is sent when the application is flashing a message. The523+ This signal is sent when the application is flashing a message. The524 messages is sent as `message` keyword argument and the category as525 `category`.526 527 Example subscriber::9 unmodified lines537 538 .. class:: signals.Namespace539 540 An alias for :class:`blinker.base.Namespace` if blinker is available,541- otherwise a dummy class that creates fake signals. This class is541+ otherwise a dummy class that creates fake signals. This class is542 available for Flask extensions that want to provide the same fallback543 system as Flask itself.544 545 .. method:: signal(name, doc=None)32 unmodified lines578 3. You can directly access the underlying Werkzeug routing system579 which is exposed as :attr:`flask.Flask.url_map`.580 581 Variable parts in the route can be specified with angular brackets582-(``/user/<username>``). By default a variable part in the URL accepts any582+(``/user/<username>``). By default a variable part in the URL accepts any583 string without a slash however a different converter can be specified as584 well by using ``<converter:name>``.585 586 Variable parts are passed to the view function as keyword arguments.25 unmodified lines612 def show_post(post_id):613 pass614 615 An important detail to keep in mind is how Flask deals with trailing616-slashes. The idea is to keep each URL unique so the following rules616+slashes. The idea is to keep each URL unique so the following rules617 apply:618 619 1. If a rule ends with a slash and is requested without a slash by the620 user, the user is automatically redirected to the same page with a621 trailing slash attached.622 2. If a rule does not end with a trailing slash and the user requests the623 page with a trailing slash, a 404 not found is raised.624 625-This is consistent with how web servers deal with static files. This625+This is consistent with how web servers deal with static files. This626 also makes it possible to use relative link targets safely.627 628-You can also define multiple rules for the same function. They have to be629-unique however. Defaults can also be specified. Here for example is a628+You can also define multiple rules for the same function. They have to be629+unique however. Defaults can also be specified. Here for example is a630 definition for a URL that accepts an optional page::631 632 @app.route('/users/', defaults={'page': 1})633 @app.route('/users/page/<int:page>')14 unmodified lines648 def region(id):649 pass650 651 Here are the parameters that :meth:`~flask.Flask.route` and652-:meth:`~flask.Flask.add_url_rule` accept. The only difference is that652+:meth:`~flask.Flask.add_url_rule` accept. The only difference is that653 with the route parameter the view function is defined with the decorator654 instead of the `view_func` parameter.655 656 =============== ==========================================================657 `rule` the URL rule as string658-`endpoint` the endpoint for the registered URL rule. Flask itself658+`endpoint` the endpoint for the registered URL rule. Flask itself659 assumes that the name of the view function is the name660 of the endpoint if not explicitly stated.661 `view_func` the function to call when serving a request to the662- provided endpoint. If this is not provided one can662+ provided endpoint. If this is not provided one can663 specify the function later by storing it in the664 :attr:`~flask.Flask.view_functions` dictionary with the665 endpoint as key.666-`defaults` A dictionary with defaults for this rule. See the666+`defaults` A dictionary with defaults for this rule. See the667 example above for how defaults work.668 `subdomain` specifies the rule for the subdomain in case subdomain669- matching is in use. If not specified the default669+ matching is in use. If not specified the default670 subdomain is assumed.671 `**options` the options to be forwarded to the underlying672- :class:`~werkzeug.routing.Rule` object. A change to673- Werkzeug is handling of method options. methods is a list672+ :class:`~werkzeug.routing.Rule` object. A change to673+ Werkzeug is handling of method options. methods is a list674 of methods this rule should be limited to (``GET``, ``POST``675- etc.). By default a rule just listens for ``GET`` (and676- implicitly ``HEAD``). Starting with Flask 0.6, ``OPTIONS`` is675+ etc.). By default a rule just listens for ``GET`` (and676+ implicitly ``HEAD``). Starting with Flask 0.6, ``OPTIONS`` is677 implicitly added and handled by the standard request678- handling. They have to be specified as keyword arguments.678+ handling. They have to be specified as keyword arguments.679 =============== ==========================================================680 681 682 View Function Options3 unmodified lines686 customize behavior the view function would normally not have control over.687 The following attributes can be provided optionally to either override688 some defaults to :meth:`~flask.Flask.add_url_rule` or general behavior:689 690-- `__name__`: The name of a function is by default used as endpoint. If691- endpoint is provided explicitly this value is used. Additionally this690+- `__name__`: The name of a function is by default used as endpoint. If691+ endpoint is provided explicitly this value is used. Additionally this692 will be prefixed with the name of the blueprint by default which693 cannot be customized from the function itself.694 695 - `methods`: If methods are not provided when the URL rule is added,696 Flask will look on the view function object itself if a `methods`697- attribute exists. If it does, it will pull the information for the697+ attribute exists. If it does, it will pull the information for the698 methods from there.699 700 - `provide_automatic_options`: if this attribute is set Flask will701 either force enable or disable the automatic implementation of the702- HTTP ``OPTIONS`` response. This can be useful when working with702+ HTTP ``OPTIONS`` response. This can be useful when working with703 decorators that want to customize the ``OPTIONS`` response on a per-view704 basis.705 706 - `required_methods`: if this attribute is set, Flask will always add44 unmodified linesmodified:requirements/dev.txt+10 added-8 removed
6 unmodified lines7 #8 -r docs.txt9 -r tests.txt10 -r typing.txt11-build==0.8.011+build==0.9.012 # via pip-tools13 cfgv==3.3.114 # via pre-commit15 click==8.1.35 unmodified lines21 filelock==3.8.022 # via23 # tox24 # virtualenv25-identify==2.5.525+identify==2.5.926 # via pre-commit27 nodeenv==1.7.028 # via pre-commit29 pep517==0.13.030 # via build31-pip-compile-multi==2.4.631+pip-compile-multi==2.6.132 # via -r requirements/dev.in33-pip-tools==6.8.033+pip-tools==6.10.034 # via pip-compile-multi35-platformdirs==2.5.235+platformdirs==2.5.436 # via virtualenv37 pre-commit==2.20.038 # via -r requirements/dev.in39+py==1.11.040+ # via tox41 pyyaml==6.042 # via pre-commit43 six==1.16.044 # via tox45 toml==0.10.246 # via pre-commit47 toposort==1.748 # via pip-compile-multi47-tox==3.26.049+tox==3.27.150 # via -r requirements/dev.in49-virtualenv==20.16.551+virtualenv==20.16.752 # via53 # pre-commit54 # tox53-wheel==0.37.155+wheel==0.38.456 # via pip-tools57 58 # The following packages are considered to be unsafe in a requirements file:59 # pip1 unmodified linemodified:requirements/docs.txt+5 added-5 removed
5 unmodified lines6 # pip-compile-multi7 #8 alabaster==0.7.129 # via sphinx10-babel==2.10.310+babel==2.11.011 # via sphinx12-certifi==2022.6.15.112+certifi==2022.9.2413 # via requests14 charset-normalizer==2.1.115 # via requests16 docutils==0.17.117 # via18 # sphinx19 # sphinx-tabs20-idna==3.320+idna==3.421 # via requests22 imagesize==1.4.123 # via sphinx24 jinja2==3.1.211 unmodified lines36 # sphinx37 # sphinx-tabs38 pyparsing==3.0.939 # via packaging40-pytz==2022.2.140+pytz==2022.641 # via babel42 requests==2.28.143 # via sphinx44 snowballstemmer==2.2.022 unmodified lines67 sphinxcontrib-qthelp==1.0.368 # via sphinx69 sphinxcontrib-serializinghtml==1.1.570 # via sphinx71-urllib3==1.26.1271+urllib3==1.26.1372 # via requestsmodified:requirements/tests.txt+1 added-7 removed
9 unmodified lines10 attrs==22.1.011 # via pytest12 blinker==1.513 # via -r requirements/tests.in14-greenlet==1.1.3 ; python_version < "3.11"15- # via -r requirements/tests.in14 iniconfig==1.1.115 # via pytest16 packaging==21.317 # via pytest18 pluggy==1.0.019 # via pytest22-py==1.11.023- # via pytest20 pyparsing==3.0.921 # via packaging26-pytest==7.1.322+pytest==7.2.023 # via -r requirements/tests.in24 python-dotenv==0.21.025 # via -r requirements/tests.in30-tomli==2.0.131- # via pytestmodified:requirements/typing.txt+4 added-6 removed
5 unmodified lines6 # pip-compile-multi7 #8 cffi==1.15.19 # via cryptography10-cryptography==38.0.110+cryptography==38.0.311 # via -r requirements/typing.in12-mypy==0.97112+mypy==0.99113 # via -r requirements/typing.in14 mypy-extensions==0.4.315 # via mypy16 pycparser==2.2117 # via cffi18-tomli==2.0.119- # via mypy18 types-contextvars==2.4.719 # via -r requirements/typing.in20 types-dataclasses==0.6.621 # via -r requirements/typing.in24-types-setuptools==65.3.022+types-setuptools==65.6.0.123 # via -r requirements/typing.in26-typing-extensions==4.3.024+typing-extensions==4.4.025 # via mypymodified:src/flask/app.py+2 added-2 removed
382 unmodified lines383 _json_encoder: t.Union[t.Type[json.JSONEncoder], None] = None384 _json_decoder: t.Union[t.Type[json.JSONDecoder], None] = None385 386 @property # type: ignore[override]387- def json_encoder(self) -> t.Type[json.JSONEncoder]: # type: ignore[override]387+ def json_encoder(self) -> t.Type[json.JSONEncoder]:388 """The JSON encoder class to use. Defaults to389 :class:`~flask.json.JSONEncoder`.390 391 .. deprecated:: 2.230 unmodified lines422 )423 self._json_encoder = value424 425 @property # type: ignore[override]426- def json_decoder(self) -> t.Type[json.JSONDecoder]: # type: ignore[override]426+ def json_decoder(self) -> t.Type[json.JSONDecoder]:427 """The JSON decoder class to use. Defaults to428 :class:`~flask.json.JSONDecoder`.429 430 .. deprecated:: 2.22121 unmodified linesmodified:src/flask/blueprints.py+4 added-4 removed
174 unmodified lines175 176 _json_encoder: t.Union[t.Type[json.JSONEncoder], None] = None177 _json_decoder: t.Union[t.Type[json.JSONDecoder], None] = None178 179- @property # type: ignore[override]180- def json_encoder( # type: ignore[override]179+ @property180+ def json_encoder(181 self,182 ) -> t.Union[t.Type[json.JSONEncoder], None]:183 """Blueprint-local JSON encoder class to use. Set to ``None`` to use the app's.184 24 unmodified lines209 stacklevel=2,210 )211 self._json_encoder = value212 213- @property # type: ignore[override]214- def json_decoder( # type: ignore[override]213+ @property214+ def json_decoder(215 self,216 ) -> t.Union[t.Type[json.JSONDecoder], None]:217 """Blueprint-local JSON decoder class to use. Set to ``None`` to use the app's.218 488 unmodified linesmodified:src/flask/ctx.py+1 added-1 removed
305 unmodified lines306 ) -> None:307 self.app = app308 if request is None:309 request = app.request_class(environ)310- request.json_module = app.json # type: ignore[misc]310+ request.json_module = app.json311 self.request: Request = request312 self.url_adapter = None313 try:314 self.url_adapter = app.create_url_adapter(self.request)124 unmodified linesmodified:src/flask/helpers.py+3 added-3 removed
147 unmodified lines148 try:149 yield from gen150 finally:151 if hasattr(gen, "close"):152- gen.close() # type: ignore152+ gen.close()153 154 # The trick is to start the generator. Then the code execution runs until155 # the first dummy None is yielded at which point the context was already156 # pushed. This item is discarded. Then when the iteration continues the129 unmodified lines286 287 return _wz_redirect(location, code=code, Response=Response)288 289 290-def abort( # type: ignore[misc]290+def abort(291 code: t.Union[int, "BaseResponse"], *args: t.Any, **kwargs: t.Any292 ) -> "te.NoReturn":293 """Raise an :exc:`~werkzeug.exceptions.HTTPException` for the given294 status code.321 unmodified lines616 if loader is None or import_name == "__main__":617 return os.getcwd()618 619 if hasattr(loader, "get_filename"):620- filepath = loader.get_filename(import_name) # type: ignore620+ filepath = loader.get_filename(import_name)621 else:622 # Fall back to imports.623 __import__(import_name)624 mod = sys.modules[import_name]81 unmodified linesmodified:src/flask/testing.py+1 added-1 removed
223 unmodified lines224 request,225 buffered=buffered,226 follow_redirects=follow_redirects,227 )228- response.json_module = self.application.json # type: ignore[misc]228+ response.json_module = self.application.json # type: ignore[assignment]229 230 # Re-push contexts that were preserved during the request.231 while self._new_contexts:232 cm = self._new_contexts.pop()54 unmodified linesmodified:src/flask/wrappers.py+1 added-1 removed
23 unmodified lines24 provides all of the attributes Werkzeug defines plus a few Flask25 specific ones.26 """27 28- json_module = json28+ json_module: t.Any = json29 30 #: The internal URL rule that matched the request. This can be31 #: useful to inspect which methods are allowed for the URL from32 #: a before/after handler (``request.url_rule.methods``) etc.139 unmodified linesmodified:tests/typing/typing_app_decorators.py+2 added-2 removed
8 unmodified lines9 10 11 @app.after_request12 def after_sync(response: Response) -> Response:13- ...13+ return Response()14 15 16 @app.after_request17 async def after_async(response: Response) -> Response:18- ...18+ return Response()19 20 21 @app.before_request22 def before_sync() -> None:16 unmodified linesmodified:.pre-commit-config.yaml+7 added-8 removed
1 unmodified line2 autoupdate_branch: "2.2.x"3 autoupdate_schedule: monthly4 repos:5 - repo: https://github.com/asottile/pyupgrade6- rev: v2.37.36+ rev: v3.2.27 hooks:8 - id: pyupgrade9- args: ["--py36-plus"]9+ args: ["--py37-plus"]10 - repo: https://github.com/asottile/reorder_python_imports11- rev: v3.8.211+ rev: v3.9.012 hooks:13 - id: reorder-python-imports14 name: Reorder Python imports (src, tests)15 files: "^(?!examples/)"16 args: ["--application-directories", "src"]17- additional_dependencies: ["setuptools>60.9"]17 - repo: https://github.com/psf/black19- rev: 22.8.018+ rev: 22.10.019 hooks:20 - id: black21 - repo: https://github.com/PyCQA/flake823- rev: 5.0.422+ rev: 6.0.023 hooks:24 - id: flake825 additional_dependencies:26 - flake8-bugbear27 - flake8-implicit-str-concat28 - repo: https://github.com/peterdemin/pip-compile-multi30- rev: v2.4.629+ rev: v2.6.130 hooks:31 - id: pip-compile-multi-verify32 - repo: https://github.com/pre-commit/pre-commit-hooks34- rev: v4.3.033+ rev: v4.4.034 hooks:35 - id: fix-byte-order-marker36 - id: trailing-whitespace37 - id: end-of-file-fixer