remove ContextVar compat

This commit is contained in:
David Lord 2021-11-11 16:12:08 -08:00
parent e609dddd60
commit 1b552d0b01
No known key found for this signature in database
GPG key ID: 7A1C87E3F5BC42A8
6 changed files with 22 additions and 13 deletions

View file

@ -7,8 +7,7 @@ Using ``async`` and ``await``
Routes, error handlers, before request, after request, and teardown Routes, error handlers, before request, after request, and teardown
functions can all be coroutine functions if Flask is installed with the functions can all be coroutine functions if Flask is installed with the
``async`` extra (``pip install flask[async]``). It requires Python 3.7+ ``async`` extra (``pip install flask[async]``). This allows views to be
where ``contextvars.ContextVar`` is available. This allows views to be
defined with ``async def`` and use ``await``. defined with ``async def`` and use ``await``.
.. code-block:: python .. code-block:: python
@ -30,6 +29,12 @@ well as all the HTTP method handlers in views that inherit from the
something like ``ValueError: set_wakeup_fd only works in main thread``, something like ``ValueError: set_wakeup_fd only works in main thread``,
please upgrade to Python 3.9. please upgrade to Python 3.9.
.. admonition:: Using ``async`` with greenlet
When using gevent or eventlet to serve an application or patch the
runtime, greenlet>=1.0 is required. When using PyPy, PyPy>=7.3.7 is
required.
Performance Performance
----------- -----------

View file

@ -49,6 +49,18 @@ use them if you install them.
.. _watchdog: https://pythonhosted.org/watchdog/ .. _watchdog: https://pythonhosted.org/watchdog/
greenlet
~~~~~~~~
You may choose to use gevent or eventlet with your application. In this
case, greenlet>=1.0 is required. When using PyPy, PyPy>=7.3.7 is
required.
These are not minimum supported versions, they only indicate the first
versions that added necessary features. You should use the latest
versions of each.
Virtual environments Virtual environments
-------------------- --------------------

View file

@ -38,7 +38,7 @@ filelock==3.3.2
# via # via
# tox # tox
# virtualenv # virtualenv
greenlet==1.1.2 greenlet==1.1.2 ; python_version < "3.11"
# via -r requirements/tests.in # via -r requirements/tests.in
identify==2.3.3 identify==2.3.3
# via pre-commit # via pre-commit

View file

@ -1,5 +1,5 @@
pytest pytest
asgiref asgiref
blinker blinker
greenlet greenlet ; python_version < "3.11"
python-dotenv python-dotenv

View file

@ -10,7 +10,7 @@ attrs==21.2.0
# via pytest # via pytest
blinker==1.4 blinker==1.4
# via -r requirements/tests.in # via -r requirements/tests.in
greenlet==1.1.2 greenlet==1.1.2 ; python_version < "3.11"
# via -r requirements/tests.in # via -r requirements/tests.in
iniconfig==1.1.1 iniconfig==1.1.1
# via pytest # via pytest

View file

@ -16,7 +16,6 @@ from werkzeug.exceptions import BadRequest
from werkzeug.exceptions import BadRequestKeyError from werkzeug.exceptions import BadRequestKeyError
from werkzeug.exceptions import HTTPException from werkzeug.exceptions import HTTPException
from werkzeug.exceptions import InternalServerError from werkzeug.exceptions import InternalServerError
from werkzeug.local import ContextVar
from werkzeug.routing import BuildError from werkzeug.routing import BuildError
from werkzeug.routing import Map from werkzeug.routing import Map
from werkzeug.routing import MapAdapter from werkzeug.routing import MapAdapter
@ -1621,13 +1620,6 @@ class Flask(Scaffold):
"Install Flask with the 'async' extra in order to use async views." "Install Flask with the 'async' extra in order to use async views."
) from None ) from None
# Check that Werkzeug isn't using its fallback ContextVar class.
if ContextVar.__module__ == "werkzeug.local":
raise RuntimeError(
"Async cannot be used with this combination of Python "
"and Greenlet versions."
)
return asgiref_async_to_sync(func) return asgiref_async_to_sync(func)
def make_response(self, rv: ResponseReturnValue) -> Response: def make_response(self, rv: ResponseReturnValue) -> Response: