From f66b5339b624f9b3d2e2cdd1e7381c8eeebce4c5 Mon Sep 17 00:00:00 2001 From: Aber Date: Sun, 7 Nov 2021 00:05:39 +0800 Subject: [PATCH 1/3] Deprecate WSGIMiddleware --- uvicorn/middleware/wsgi.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/uvicorn/middleware/wsgi.py b/uvicorn/middleware/wsgi.py index 74bdfada4..f03746980 100644 --- a/uvicorn/middleware/wsgi.py +++ b/uvicorn/middleware/wsgi.py @@ -2,6 +2,7 @@ import concurrent.futures import io import sys +import warnings from collections import deque from typing import Deque, Iterable, Optional, Tuple @@ -72,6 +73,10 @@ def build_environ(scope: HTTPScope, message: ASGIReceiveEvent, body: bytes) -> E class WSGIMiddleware: def __init__(self, app: WSGIApp, workers: int = 10): + warnings.warn( + "The built-in `WSGIMiddleware` will be deprecated in future versions, please use `a2wsgi.WSGIMiddleware` instead.", + DeprecationWarning, + ) self.app = app self.executor = concurrent.futures.ThreadPoolExecutor(max_workers=workers) From 25b4178c63ec2a4c37e79bc5ea247392f9316376 Mon Sep 17 00:00:00 2001 From: Aber Date: Sun, 7 Nov 2021 00:07:57 +0800 Subject: [PATCH 2/3] fixed pep8 --- uvicorn/middleware/wsgi.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/uvicorn/middleware/wsgi.py b/uvicorn/middleware/wsgi.py index f03746980..e20e2d2ff 100644 --- a/uvicorn/middleware/wsgi.py +++ b/uvicorn/middleware/wsgi.py @@ -74,7 +74,8 @@ def build_environ(scope: HTTPScope, message: ASGIReceiveEvent, body: bytes) -> E class WSGIMiddleware: def __init__(self, app: WSGIApp, workers: int = 10): warnings.warn( - "The built-in `WSGIMiddleware` will be deprecated in future versions, please use `a2wsgi.WSGIMiddleware` instead.", + "The built-in `WSGIMiddleware` will be deprecated in" + " future versions, please use `a2wsgi.WSGIMiddleware` instead.", DeprecationWarning, ) self.app = app From e581e04449225af89e8ec8ed6e0583e50d58b204 Mon Sep 17 00:00:00 2001 From: Aber Date: Fri, 12 Nov 2021 02:34:45 +0000 Subject: [PATCH 3/3] fix DeprecationWarning --- setup.cfg | 1 + uvicorn/middleware/wsgi.py | 11 ++++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/setup.cfg b/setup.cfg index 7f218b27b..66a81dd5a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -64,6 +64,7 @@ filterwarnings= error # Workaround for Python 3.9.7 (see https://bugs.python.org/issue45097) ignore:The loop argument is deprecated since Python 3\.8, and scheduled for removal in Python 3\.10\.:DeprecationWarning:asyncio + ignore:The built-in `WSGIMiddleware` will be deprecated in future versions, please use `a2wsgi.WSGIMiddleware` instead.:DeprecationWarning [coverage:run] omit = venv/* diff --git a/uvicorn/middleware/wsgi.py b/uvicorn/middleware/wsgi.py index e20e2d2ff..7155652b3 100644 --- a/uvicorn/middleware/wsgi.py +++ b/uvicorn/middleware/wsgi.py @@ -19,6 +19,12 @@ from uvicorn._types import Environ, ExcInfo, StartResponse, WSGIApp +warnings.warn( + "The built-in `WSGIMiddleware` will be deprecated in" + " future versions, please use `a2wsgi.WSGIMiddleware` instead.", + DeprecationWarning, +) + def build_environ(scope: HTTPScope, message: ASGIReceiveEvent, body: bytes) -> Environ: """ @@ -73,11 +79,6 @@ def build_environ(scope: HTTPScope, message: ASGIReceiveEvent, body: bytes) -> E class WSGIMiddleware: def __init__(self, app: WSGIApp, workers: int = 10): - warnings.warn( - "The built-in `WSGIMiddleware` will be deprecated in" - " future versions, please use `a2wsgi.WSGIMiddleware` instead.", - DeprecationWarning, - ) self.app = app self.executor = concurrent.futures.ThreadPoolExecutor(max_workers=workers)