From 26aa6d23c7b7b2a9caa652a94efaa909446014c6 Mon Sep 17 00:00:00 2001 From: Adam Hopkins Date: Tue, 7 Jul 2020 16:13:03 +0300 Subject: [PATCH] Fix imports and isort to remove from Makefile deprecated options (#1891) * Version * Version 20.6.1 * Fix imports and isort to remove from Makefile deprecated options * duplicate the mypy ignore hint across both lines after splitting the `from trio import ...` statement onto two lines, need to duplicate the mypy ignore hint across both lines to keep mypy from complaining Co-authored-by: Ashley Sommer --- Makefile | 2 +- sanic/compat.py | 3 ++- sanic/response.py | 4 ++-- sanic/worker.py | 2 +- tests/performance/wheezy/simple_server.py | 2 +- tests/test_requests.py | 5 +---- 6 files changed, 8 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index a5af7243..519c74ec 100644 --- a/Makefile +++ b/Makefile @@ -71,7 +71,7 @@ black: black --config ./.black.toml sanic tests fix-import: black - isort -rc sanic tests + isort sanic tests docs-clean: diff --git a/sanic/compat.py b/sanic/compat.py index 28c91b97..f6244426 100644 --- a/sanic/compat.py +++ b/sanic/compat.py @@ -14,7 +14,8 @@ class Header(CIMultiDict): use_trio = argv[0].endswith("hypercorn") and "trio" in argv if use_trio: - from trio import open_file as open_async, Path # type: ignore + from trio import Path # type: ignore + from trio import open_file as open_async # type: ignore def stat_async(path): return Path(path).stat() diff --git a/sanic/response.py b/sanic/response.py index 6f02a35c..2ebf0046 100644 --- a/sanic/response.py +++ b/sanic/response.py @@ -14,10 +14,10 @@ from sanic.helpers import has_message_body, remove_entity_headers try: from ujson import dumps as json_dumps except ImportError: - from json import dumps - # This is done in order to ensure that the JSON response is # kept consistent across both ujson and inbuilt json usage. + from json import dumps + json_dumps = partial(dumps, separators=(",", ":")) diff --git a/sanic/worker.py b/sanic/worker.py index 777f12cf..b217b992 100644 --- a/sanic/worker.py +++ b/sanic/worker.py @@ -5,7 +5,7 @@ import signal import sys import traceback -import gunicorn.workers.base as base # type: ignore +from gunicorn.workers import base as base # type: ignore from sanic.server import HttpProtocol, Signal, serve, trigger_events from sanic.websocket import WebSocketProtocol diff --git a/tests/performance/wheezy/simple_server.py b/tests/performance/wheezy/simple_server.py index 70a6338a..f5db80b4 100644 --- a/tests/performance/wheezy/simple_server.py +++ b/tests/performance/wheezy/simple_server.py @@ -1,7 +1,6 @@ # Run with: gunicorn --workers=1 --worker-class=meinheld.gmeinheld.MeinheldWorker simple_server:main """ Minimal helloworld application. """ - import ujson from wheezy.http import HTTPResponse, WSGIApplication @@ -39,6 +38,7 @@ main = WSGIApplication( if __name__ == "__main__": import sys + from wsgiref.simple_server import make_server try: diff --git a/tests/test_requests.py b/tests/test_requests.py index 31883e37..1ed94359 100644 --- a/tests/test_requests.py +++ b/tests/test_requests.py @@ -1955,10 +1955,7 @@ def test_server_name_and_url_for(app): app.config.SERVER_NAME = "my-server" # This means default port assert app.url_for("handler", _external=True) == "http://my-server/foo" request, response = app.test_client.get("/foo") - assert ( - request.url_for("handler") - == f"http://my-server/foo" - ) + assert request.url_for("handler") == f"http://my-server/foo" app.config.SERVER_NAME = "https://my-server/path" request, response = app.test_client.get("/foo")