From 1b552d0b0163e1c1ae3d4895438a9ce2b2bc098e Mon Sep 17 00:00:00 2001 From: David Lord Date: Thu, 11 Nov 2021 16:12:08 -0800 Subject: [PATCH] remove ContextVar compat --- docs/async-await.rst | 9 +++++++-- docs/installation.rst | 12 ++++++++++++ requirements/dev.txt | 2 +- requirements/tests.in | 2 +- requirements/tests.txt | 2 +- src/flask/app.py | 8 -------- 6 files changed, 22 insertions(+), 13 deletions(-) diff --git a/docs/async-await.rst b/docs/async-await.rst index 71e5f452..4c70f961 100644 --- a/docs/async-await.rst +++ b/docs/async-await.rst @@ -7,8 +7,7 @@ Using ``async`` and ``await`` Routes, error handlers, before request, after request, and teardown functions can all be coroutine functions if Flask is installed with the -``async`` extra (``pip install flask[async]``). It requires Python 3.7+ -where ``contextvars.ContextVar`` is available. This allows views to be +``async`` extra (``pip install flask[async]``). This allows views to be defined with ``async def`` and use ``await``. .. 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``, 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 ----------- diff --git a/docs/installation.rst b/docs/installation.rst index 6007bbb7..8a338e18 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -49,6 +49,18 @@ use them if you install them. .. _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 -------------------- diff --git a/requirements/dev.txt b/requirements/dev.txt index b87571ff..33493af3 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -38,7 +38,7 @@ filelock==3.3.2 # via # tox # virtualenv -greenlet==1.1.2 +greenlet==1.1.2 ; python_version < "3.11" # via -r requirements/tests.in identify==2.3.3 # via pre-commit diff --git a/requirements/tests.in b/requirements/tests.in index 88fe5481..41936997 100644 --- a/requirements/tests.in +++ b/requirements/tests.in @@ -1,5 +1,5 @@ pytest asgiref blinker -greenlet +greenlet ; python_version < "3.11" python-dotenv diff --git a/requirements/tests.txt b/requirements/tests.txt index a86b6041..4e4247f5 100644 --- a/requirements/tests.txt +++ b/requirements/tests.txt @@ -10,7 +10,7 @@ attrs==21.2.0 # via pytest blinker==1.4 # via -r requirements/tests.in -greenlet==1.1.2 +greenlet==1.1.2 ; python_version < "3.11" # via -r requirements/tests.in iniconfig==1.1.1 # via pytest diff --git a/src/flask/app.py b/src/flask/app.py index 23b99e2c..7c4076c5 100644 --- a/src/flask/app.py +++ b/src/flask/app.py @@ -16,7 +16,6 @@ from werkzeug.exceptions import BadRequest from werkzeug.exceptions import BadRequestKeyError from werkzeug.exceptions import HTTPException from werkzeug.exceptions import InternalServerError -from werkzeug.local import ContextVar from werkzeug.routing import BuildError from werkzeug.routing import Map from werkzeug.routing import MapAdapter @@ -1621,13 +1620,6 @@ class Flask(Scaffold): "Install Flask with the 'async' extra in order to use async views." ) 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) def make_response(self, rv: ResponseReturnValue) -> Response: