Skip to content
Myr

remove ContextVar compat

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 e609ddd · Browse files · 6 files+22 added−13 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

6 files+22 added−13 removed

  • other:+22 added−13 removed

6 files+22 added−13 removed

modified:docs/async-await.rst+7 added-2 removed
5 unmodified lines
6.. versionadded:: 2.078Routes, error handlers, before request, after request, and teardown9functions can all be coroutine functions if Flask is installed with the10``async`` extra (``pip install flask[async]``). It requires Python 3.7+11where ``contextvars.ContextVar`` is available. This allows views to be10``async`` extra (``pip install flask[async]``). This allows views to be11defined with ``async def`` and use ``await``.1213.. code-block:: python14
13 unmodified lines
28 Python 3.8 has a bug related to asyncio on Windows. If you encounter29 something like ``ValueError: set_wakeup_fd only works in main thread``,30 please upgrade to Python 3.9.3132.. admonition:: Using ``async`` with greenlet3334 When using gevent or eventlet to serve an application or patch the35 runtime, greenlet>=1.0 is required. When using PyPy, PyPy>=7.3.7 is36 required.373839Performance40-----------4142Async functions require an event loop to run. Flask, as a WSGI
89 unmodified lines
modified:docs/installation.rst+12 added
47 unmodified lines
48.. _python-dotenv: https://github.com/theskumar/python-dotenv#readme49.. _watchdog: https://pythonhosted.org/watchdog/505152greenlet53~~~~~~~~5455You may choose to use gevent or eventlet with your application. In this56case, greenlet>=1.0 is required. When using PyPy, PyPy>=7.3.7 is57required.5859These are not minimum supported versions, they only indicate the first60versions that added necessary features. You should use the latest61versions of each.626364Virtual environments65--------------------6667Use a virtual environment to manage the dependencies for your project, both in
78 unmodified lines
modified:requirements/dev.txt+1 added-1 removed
36 unmodified lines
37filelock==3.3.238 # via39 # tox40 # virtualenv41greenlet==1.1.241greenlet==1.1.2 ; python_version < "3.11"42 # via -r requirements/tests.in43identify==2.3.344 # via pre-commit45idna==3.3
118 unmodified lines
modified:requirements/tests.in+1 added-1 removed
1pytest2asgiref3blinker4greenlet4greenlet ; python_version < "3.11"5python-dotenv
modified:requirements/tests.txt+1 added-1 removed
8 unmodified lines
9attrs==21.2.010 # via pytest11blinker==1.412 # via -r requirements/tests.in13greenlet==1.1.213greenlet==1.1.2 ; python_version < "3.11"14 # via -r requirements/tests.in15iniconfig==1.1.116 # via pytest17packaging==21.2
13 unmodified lines
modified:src/flask/app.py-8 removed
14 unmodified lines
15from werkzeug.exceptions import BadRequest16from werkzeug.exceptions import BadRequestKeyError17from werkzeug.exceptions import HTTPException18from werkzeug.exceptions import InternalServerError19from werkzeug.local import ContextVar19from werkzeug.routing import BuildError20from werkzeug.routing import Map21from werkzeug.routing import MapAdapter22from werkzeug.routing import RequestRedirect
1596 unmodified lines
1619 raise RuntimeError(1620 "Install Flask with the 'async' extra in order to use async views."1621 ) from None16221624 # Check that Werkzeug isn't using its fallback ContextVar class.1625 if ContextVar.__module__ == "werkzeug.local":1626 raise RuntimeError(1627 "Async cannot be used with this combination of Python "1628 "and Greenlet versions."1629 )16301623 return asgiref_async_to_sync(func)16241625 def make_response(self, rv: ResponseReturnValue) -> Response:1626 """Convert the return value from a view function to an instance of
457 unmodified lines