From e4daf1ab21404a0224ef25926bdbccceaa84c310 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=2E=20K=C3=A4rkk=C3=A4inen?= Date: Wed, 25 Oct 2023 04:12:24 +0100 Subject: [PATCH] Removed flake8, black and isort; moving towards ruff default settings instead. --- docs/conf.py | 2 -- examples/add_task_sanic.py | 1 - examples/amending_request_object.py | 1 - examples/authorized_sanic.py | 1 - .../blueprint_middlware_execution_order.py | 1 - examples/blueprints.py | 1 - examples/delayed_response.py | 1 - examples/exception_monitoring.py | 2 -- examples/hello_world.py | 1 - examples/http_redirect.py | 1 - examples/limit_concurrency.py | 1 - examples/log_request_id.py | 2 -- examples/logdna_example.py | 2 -- examples/modify_header_example.py | 1 - examples/override_logging.py | 1 - examples/pytest_xdist.py | 1 - examples/redirect_example.py | 1 - examples/request_stream/client.py | 1 - examples/request_stream/server.py | 1 - examples/request_timeout.py | 1 - examples/rollbar_example.py | 1 - examples/run_asgi.py | 1 - examples/run_async.py | 1 - examples/run_async_advanced.py | 2 -- examples/sentry_example.py | 1 - examples/simple_async_view.py | 1 - examples/static_assets.py | 1 - examples/teapot.py | 1 - examples/try_everything.py | 1 - examples/unix_socket.py | 1 - examples/url_for_example.py | 1 - examples/versioned_blueprint_group.py | 1 - examples/vhosts.py | 1 - examples/websocket.py | 1 - guide/content/en/migrate.py | 2 -- guide/server.py | 1 - guide/webapp/display/markdown.py | 1 - guide/webapp/display/page/__init__.py | 1 - guide/webapp/display/page/docobject.py | 1 - guide/webapp/display/page/page.py | 1 - guide/webapp/display/text.py | 1 - guide/webapp/endpoint/search.py | 1 - guide/webapp/endpoint/view.py | 1 - guide/webapp/worker/reload.py | 1 - pyproject.toml | 18 ------------------ sanic/__init__.py | 1 - sanic/__main__.py | 1 - sanic/app.py | 6 ++---- sanic/application/ext.py | 1 - sanic/application/logo.py | 2 -- sanic/application/spinner.py | 2 -- sanic/application/state.py | 2 -- sanic/asgi.py | 2 -- sanic/base/root.py | 2 -- sanic/blueprint_group.py | 1 - sanic/blueprints.py | 2 -- sanic/cli/app.py | 1 - sanic/cli/inspector_client.py | 2 -- sanic/compat.py | 2 -- sanic/config.py | 1 - sanic/cookies/__init__.py | 1 - sanic/cookies/request.py | 2 -- sanic/cookies/response.py | 3 --- sanic/errorpages.py | 2 -- sanic/handlers/__init__.py | 1 - sanic/handlers/content_range.py | 2 -- sanic/headers.py | 2 -- sanic/helpers.py | 2 -- sanic/http/__init__.py | 1 - sanic/http/http1.py | 2 -- sanic/http/http3.py | 2 -- sanic/http/stream.py | 1 - sanic/http/tls/__init__.py | 1 - sanic/http/tls/context.py | 2 -- sanic/http/tls/creators.py | 2 -- sanic/log.py | 2 -- sanic/mixins/routes.py | 1 - sanic/mixins/startup.py | 3 --- sanic/models/asgi.py | 2 -- sanic/models/handler_types.py | 2 -- sanic/models/protocol_types.py | 1 - sanic/pages/css.py | 1 - sanic/pages/error.py | 2 -- sanic/request/__init__.py | 1 - sanic/request/form.py | 1 - sanic/request/types.py | 3 --- sanic/response/__init__.py | 1 - sanic/response/types.py | 1 - sanic/router.py | 1 - sanic/server/__init__.py | 1 - sanic/server/async_server.py | 2 -- sanic/server/events.py | 1 - sanic/server/loop.py | 1 - sanic/server/protocols/base_protocol.py | 2 -- sanic/server/protocols/http_protocol.py | 3 --- sanic/server/protocols/websocket_protocol.py | 2 -- sanic/server/runners.py | 3 --- sanic/server/socket.py | 1 - sanic/server/websockets/connection.py | 1 - sanic/server/websockets/frame.py | 2 -- sanic/server/websockets/impl.py | 3 --- sanic/signals.py | 1 - sanic/touchup/__init__.py | 1 - sanic/touchup/schemes/altsvc.py | 1 - sanic/types/__init__.py | 1 - sanic/types/shared_ctx.py | 1 - sanic/utils.py | 1 - sanic/views.py | 1 - sanic/worker/loader.py | 2 -- sanic/worker/manager.py | 2 -- sanic/worker/process.py | 1 - sanic/worker/reloader.py | 1 - sanic/worker/serve.py | 1 - sanic/worker/state.py | 1 - scripts/changelog.py | 2 -- scripts/release.py | 7 +------ setup.py | 4 +--- .../test_route_resolution_benchmark.py | 2 -- tests/client.py | 1 - tests/conftest.py | 3 --- tests/fake/server.py | 1 - tests/http3/test_http_receiver.py | 2 -- tests/http3/test_server.py | 2 -- tests/performance/aiohttp/simple_server.py | 2 -- tests/performance/bottle/simple_server.py | 1 - tests/performance/kyoukai/simple_server.py | 2 -- tests/performance/sanic/http_response.py | 1 - tests/performance/sanic/simple_server.py | 1 - tests/performance/sanic/varied_server.py | 1 - tests/performance/tornado/simple_server.py | 1 - tests/performance/wheezy/simple_server.py | 2 -- tests/test_app.py | 2 -- tests/test_asgi.py | 3 --- tests/test_blueprint_copy.py | 1 - tests/test_blueprint_group.py | 2 -- tests/test_blueprints.py | 1 - tests/test_cli.py | 2 -- tests/test_coffee.py | 1 - tests/test_config.py | 2 -- tests/test_cookies.py | 1 - tests/test_create_task.py | 1 - tests/test_dynamic_routes.py | 1 - tests/test_errorpages.py | 1 - tests/test_exceptions.py | 1 - tests/test_exceptions_handler.py | 2 -- tests/test_ext_integration.py | 1 - tests/test_graceful_shutdown.py | 1 - tests/test_http.py | 3 --- tests/test_http_alt_svc.py | 2 -- tests/test_json_decoding.py | 1 - tests/test_json_encoding.py | 3 --- tests/test_keep_alive_timeout.py | 3 --- tests/test_logging.py | 3 --- tests/test_logo.py | 1 - tests/test_middleware.py | 2 -- tests/test_middleware_priority.py | 1 - tests/test_motd.py | 1 - tests/test_multiprocessing.py | 2 -- tests/test_named_routes.py | 1 - tests/test_prepare.py | 1 - tests/test_reloader.py | 2 -- tests/test_request.py | 1 - tests/test_request_data.py | 1 - tests/test_request_stream.py | 1 - tests/test_requests.py | 2 -- tests/test_response.py | 3 --- tests/test_response_json.py | 2 -- tests/test_response_timeout.py | 1 - tests/test_routes.py | 1 - tests/test_server_events.py | 3 --- tests/test_server_loop.py | 1 - tests/test_signal_handlers.py | 2 -- tests/test_signals.py | 2 -- tests/test_static.py | 1 - tests/test_static_directory.py | 1 - tests/test_tasks.py | 2 -- tests/test_test_client_port.py | 1 - tests/test_timeout_logic.py | 1 - tests/test_tls.py | 4 ---- tests/test_touchup.py | 1 - tests/test_unix_socket.py | 3 --- tests/test_url_building.py | 3 --- tests/test_url_for.py | 1 - tests/test_utf8.py | 1 - tests/test_vhosts.py | 1 - tests/test_websockets.py | 3 --- tests/test_ws_handlers.py | 2 -- tests/typing/samples/app_default.py | 1 - tests/typing/test_typing.py | 2 -- tests/worker/test_inspector.py | 2 -- tests/worker/test_loader.py | 2 -- tests/worker/test_manager.py | 1 - tests/worker/test_multiplexer.py | 1 - tests/worker/test_reloader.py | 1 - tests/worker/test_shared_ctx.py | 1 - tests/worker/test_worker_serve.py | 1 - tox.ini | 5 ++--- 197 files changed, 6 insertions(+), 321 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 4a55cb66..a612844c 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -9,7 +9,6 @@ import os import sys - # Add support for auto-doc @@ -20,7 +19,6 @@ sys.path.insert(0, root_directory) import sanic # noqa: E402 - # -- General configuration ------------------------------------------------ extensions = [ diff --git a/examples/add_task_sanic.py b/examples/add_task_sanic.py index 2ff86033..539788a5 100644 --- a/examples/add_task_sanic.py +++ b/examples/add_task_sanic.py @@ -2,7 +2,6 @@ import asyncio from sanic import Sanic - app = Sanic("Example") diff --git a/examples/amending_request_object.py b/examples/amending_request_object.py index 3c5bb59d..80902594 100644 --- a/examples/amending_request_object.py +++ b/examples/amending_request_object.py @@ -3,7 +3,6 @@ from random import randint from sanic import Sanic from sanic.response import text - app = Sanic("Example") diff --git a/examples/authorized_sanic.py b/examples/authorized_sanic.py index 9842f770..4f1c83ef 100644 --- a/examples/authorized_sanic.py +++ b/examples/authorized_sanic.py @@ -3,7 +3,6 @@ from functools import wraps from sanic import Sanic from sanic.response import json - app = Sanic("Example") diff --git a/examples/blueprint_middlware_execution_order.py b/examples/blueprint_middlware_execution_order.py index b0448da8..11a88e4f 100644 --- a/examples/blueprint_middlware_execution_order.py +++ b/examples/blueprint_middlware_execution_order.py @@ -1,7 +1,6 @@ from sanic import Blueprint, Sanic from sanic.response import text - """ Demonstrates that blueprint request middleware are executed in the order they are added. And blueprint response middleware are executed in _reverse_ order. diff --git a/examples/blueprints.py b/examples/blueprints.py index e368573b..75a81a15 100644 --- a/examples/blueprints.py +++ b/examples/blueprints.py @@ -1,7 +1,6 @@ from sanic import Blueprint, Sanic from sanic.response import file, json - app = Sanic("Example") blueprint = Blueprint("bp_example", url_prefix="/my_blueprint") blueprint2 = Blueprint("bp_example2", url_prefix="/my_blueprint2") diff --git a/examples/delayed_response.py b/examples/delayed_response.py index 91e24773..07698aed 100644 --- a/examples/delayed_response.py +++ b/examples/delayed_response.py @@ -2,7 +2,6 @@ from asyncio import sleep from sanic import Sanic, response - app = Sanic("DelayedResponseApp", strict_slashes=True) app.config.AUTO_EXTEND = False diff --git a/examples/exception_monitoring.py b/examples/exception_monitoring.py index eb52ed9a..17cd7127 100644 --- a/examples/exception_monitoring.py +++ b/examples/exception_monitoring.py @@ -10,7 +10,6 @@ an external service. from sanic.exceptions import SanicException from sanic.handlers import ErrorHandler - """ Imports and code relevant for our CustomHandler class (Ordinarily this would be in a separate file) @@ -39,7 +38,6 @@ server's error_handler to an instance of our CustomHandler from sanic import Sanic - handler = CustomHandler() app = Sanic("Example", error_handler=handler) diff --git a/examples/hello_world.py b/examples/hello_world.py index 9e45b856..cacfbd67 100644 --- a/examples/hello_world.py +++ b/examples/hello_world.py @@ -1,6 +1,5 @@ from sanic import Sanic, response - app = Sanic("Example") diff --git a/examples/http_redirect.py b/examples/http_redirect.py index 2a8c69c5..b13ee8bd 100644 --- a/examples/http_redirect.py +++ b/examples/http_redirect.py @@ -2,7 +2,6 @@ from sanic import Sanic, response, text from sanic.handlers import ErrorHandler from sanic.server.async_server import AsyncioServer - HTTP_PORT = 9999 HTTPS_PORT = 8888 diff --git a/examples/limit_concurrency.py b/examples/limit_concurrency.py index e97f964a..4e3636af 100644 --- a/examples/limit_concurrency.py +++ b/examples/limit_concurrency.py @@ -5,7 +5,6 @@ import httpx from sanic import Sanic from sanic.response import json - app = Sanic("Example") sem = None diff --git a/examples/log_request_id.py b/examples/log_request_id.py index 87825640..2d845d65 100644 --- a/examples/log_request_id.py +++ b/examples/log_request_id.py @@ -1,10 +1,8 @@ import logging - from contextvars import ContextVar from sanic import Sanic, response - log = logging.getLogger(__name__) diff --git a/examples/logdna_example.py b/examples/logdna_example.py index 01004509..9dc9ee40 100644 --- a/examples/logdna_example.py +++ b/examples/logdna_example.py @@ -1,6 +1,5 @@ import logging import socket - from os import getenv from platform import node from uuid import getnode as get_mac @@ -11,7 +10,6 @@ from sanic import Sanic from sanic.request import Request from sanic.response import json - log = logging.getLogger("logdna") log.setLevel(logging.INFO) diff --git a/examples/modify_header_example.py b/examples/modify_header_example.py index 6455cb85..db3cf063 100644 --- a/examples/modify_header_example.py +++ b/examples/modify_header_example.py @@ -4,7 +4,6 @@ Modify header or status in response from sanic import Sanic, response - app = Sanic("Example") diff --git a/examples/override_logging.py b/examples/override_logging.py index ebc0e86f..020b933e 100644 --- a/examples/override_logging.py +++ b/examples/override_logging.py @@ -2,7 +2,6 @@ import logging from sanic import Sanic, text - logging_format = "[%(asctime)s] %(process)d-%(levelname)s " logging_format += "%(module)s::%(funcName)s():l%(lineno)d: " logging_format += "%(message)s" diff --git a/examples/pytest_xdist.py b/examples/pytest_xdist.py index 7adeb93a..920d987d 100644 --- a/examples/pytest_xdist.py +++ b/examples/pytest_xdist.py @@ -11,7 +11,6 @@ Run with xdist params: import re import pytest - from sanic_testing import SanicTestClient from sanic_testing.testing import PORT as PORT_BASE diff --git a/examples/redirect_example.py b/examples/redirect_example.py index 74fb10de..50200f90 100644 --- a/examples/redirect_example.py +++ b/examples/redirect_example.py @@ -1,6 +1,5 @@ from sanic import Sanic, response - app = Sanic("Example") diff --git a/examples/request_stream/client.py b/examples/request_stream/client.py index b9565634..c6c4f73d 100644 --- a/examples/request_stream/client.py +++ b/examples/request_stream/client.py @@ -1,6 +1,5 @@ import requests - # Warning: This is a heavy process. data = "" diff --git a/examples/request_stream/server.py b/examples/request_stream/server.py index bffc7451..9f7b77f3 100644 --- a/examples/request_stream/server.py +++ b/examples/request_stream/server.py @@ -4,7 +4,6 @@ from sanic.response import stream, text from sanic.views import HTTPMethodView from sanic.views import stream as stream_decorator - bp = Blueprint("bp_example") app = Sanic("Example") diff --git a/examples/request_timeout.py b/examples/request_timeout.py index 07934b0c..1be8b875 100644 --- a/examples/request_timeout.py +++ b/examples/request_timeout.py @@ -4,7 +4,6 @@ from sanic import Sanic, response from sanic.config import Config from sanic.exceptions import RequestTimeout - Config.REQUEST_TIMEOUT = 1 app = Sanic("Example") diff --git a/examples/rollbar_example.py b/examples/rollbar_example.py index 53d53c5a..c63f6f5f 100644 --- a/examples/rollbar_example.py +++ b/examples/rollbar_example.py @@ -6,7 +6,6 @@ from sanic import Sanic from sanic.exceptions import SanicException from sanic.handlers import ErrorHandler - rollbar.init(getenv("ROLLBAR_API_KEY")) diff --git a/examples/run_asgi.py b/examples/run_asgi.py index bc559789..81a7cd8a 100644 --- a/examples/run_asgi.py +++ b/examples/run_asgi.py @@ -10,7 +10,6 @@ from pathlib import Path from sanic import Sanic, response - app = Sanic("Example") diff --git a/examples/run_async.py b/examples/run_async.py index 84c8a6be..a627a59e 100644 --- a/examples/run_async.py +++ b/examples/run_async.py @@ -4,7 +4,6 @@ import uvloop from sanic import Sanic, response - app = Sanic("Example") diff --git a/examples/run_async_advanced.py b/examples/run_async_advanced.py index 917beefa..fa8ffec6 100644 --- a/examples/run_async_advanced.py +++ b/examples/run_async_advanced.py @@ -1,5 +1,4 @@ import asyncio - from signal import SIGINT, signal import uvloop @@ -7,7 +6,6 @@ import uvloop from sanic import Sanic, response from sanic.server import AsyncioServer - app = Sanic("Example") diff --git a/examples/sentry_example.py b/examples/sentry_example.py index 1dfc1ba4..753af0b7 100644 --- a/examples/sentry_example.py +++ b/examples/sentry_example.py @@ -6,7 +6,6 @@ from sentry_sdk.integrations.sanic import SanicIntegration from sanic import Sanic from sanic.response import json - sentry_init( dsn=getenv("SENTRY_DSN"), integrations=[SanicIntegration()], diff --git a/examples/simple_async_view.py b/examples/simple_async_view.py index 4e73967c..f0690dae 100644 --- a/examples/simple_async_view.py +++ b/examples/simple_async_view.py @@ -2,7 +2,6 @@ from sanic import Sanic from sanic.response import text from sanic.views import HTTPMethodView - app = Sanic("some_name") diff --git a/examples/static_assets.py b/examples/static_assets.py index 347b489c..7cd223b3 100644 --- a/examples/static_assets.py +++ b/examples/static_assets.py @@ -1,6 +1,5 @@ from sanic import Sanic - app = Sanic("Example") app.static("/", "./static") diff --git a/examples/teapot.py b/examples/teapot.py index 5d742efc..5c52fb69 100644 --- a/examples/teapot.py +++ b/examples/teapot.py @@ -1,7 +1,6 @@ from sanic import Sanic from sanic import response as res - app = Sanic("Example") diff --git a/examples/try_everything.py b/examples/try_everything.py index 92310d25..6020388d 100644 --- a/examples/try_everything.py +++ b/examples/try_everything.py @@ -4,7 +4,6 @@ from sanic import Sanic, response from sanic.exceptions import ServerError from sanic.log import logger as log - app = Sanic("Example") diff --git a/examples/unix_socket.py b/examples/unix_socket.py index 347c46b2..608502ad 100644 --- a/examples/unix_socket.py +++ b/examples/unix_socket.py @@ -1,6 +1,5 @@ from sanic import Sanic, response - app = Sanic("Example") diff --git a/examples/url_for_example.py b/examples/url_for_example.py index 637481fc..f855c505 100644 --- a/examples/url_for_example.py +++ b/examples/url_for_example.py @@ -1,6 +1,5 @@ from sanic import Sanic, response - app = Sanic("Example") diff --git a/examples/versioned_blueprint_group.py b/examples/versioned_blueprint_group.py index 56715acc..e9812dcf 100644 --- a/examples/versioned_blueprint_group.py +++ b/examples/versioned_blueprint_group.py @@ -2,7 +2,6 @@ from sanic import Sanic from sanic.blueprints import Blueprint from sanic.response import json - app = Sanic(name="blue-print-group-version-example") bp1 = Blueprint(name="ultron", url_prefix="/ultron") diff --git a/examples/vhosts.py b/examples/vhosts.py index 335a3be8..0c3482e4 100644 --- a/examples/vhosts.py +++ b/examples/vhosts.py @@ -1,7 +1,6 @@ from sanic import Sanic, response from sanic.blueprints import Blueprint - # Usage # curl -H "Host: example.com" localhost:8000 # curl -H "Host: sub.example.com" localhost:8000 diff --git a/examples/websocket.py b/examples/websocket.py index ce5a105c..c273ee98 100644 --- a/examples/websocket.py +++ b/examples/websocket.py @@ -1,7 +1,6 @@ from sanic import Sanic from sanic.response import redirect - app = Sanic("Example") diff --git a/guide/content/en/migrate.py b/guide/content/en/migrate.py index bc783c6f..e0510af4 100644 --- a/guide/content/en/migrate.py +++ b/guide/content/en/migrate.py @@ -1,11 +1,9 @@ import re - from pathlib import Path from textwrap import indent from emoji import EMOJI - COLUMN_PATTERN = re.compile(r"---:1\s*(.*?)\s*:--:1\s*(.*?)\s*:---", re.DOTALL) PYTHON_HIGHLIGHT_PATTERN = re.compile(r"```python\{+.*?\}", re.DOTALL) BASH_HIGHLIGHT_PATTERN = re.compile(r"```bash\{+.*?\}", re.DOTALL) diff --git a/guide/server.py b/guide/server.py index 00db05bd..9de1c500 100644 --- a/guide/server.py +++ b/guide/server.py @@ -2,5 +2,4 @@ from pathlib import Path from webapp.worker.factory import create_app - app = create_app(Path(__file__).parent) diff --git a/guide/webapp/display/markdown.py b/guide/webapp/display/markdown.py index d517ddcc..eb76cb81 100644 --- a/guide/webapp/display/markdown.py +++ b/guide/webapp/display/markdown.py @@ -1,5 +1,4 @@ import re - from textwrap import dedent from html5tagger import HTML, Builder, E # type: ignore diff --git a/guide/webapp/display/page/__init__.py b/guide/webapp/display/page/__init__.py index 7a873876..7ad390fc 100644 --- a/guide/webapp/display/page/__init__.py +++ b/guide/webapp/display/page/__init__.py @@ -1,5 +1,4 @@ from .page import Page from .renderer import PageRenderer - __all__ = ["Page", "PageRenderer"] diff --git a/guide/webapp/display/page/docobject.py b/guide/webapp/display/page/docobject.py index 8287a4ad..e35f90fd 100644 --- a/guide/webapp/display/page/docobject.py +++ b/guide/webapp/display/page/docobject.py @@ -3,7 +3,6 @@ from __future__ import annotations import importlib import inspect import pkgutil - from collections import defaultdict from dataclasses import dataclass, field from html import escape diff --git a/guide/webapp/display/page/page.py b/guide/webapp/display/page/page.py index b4ddde58..a2c9d4cb 100644 --- a/guide/webapp/display/page/page.py +++ b/guide/webapp/display/page/page.py @@ -11,7 +11,6 @@ from ..layouts.main import MainLayout from ..markdown import render_markdown from .docobject import organize_docobjects - _PAGE_CACHE: dict[ str, dict[str, tuple[Page | None, Page | None, Page | None]] ] = {} diff --git a/guide/webapp/display/text.py b/guide/webapp/display/text.py index 2157da7e..00518cdc 100644 --- a/guide/webapp/display/text.py +++ b/guide/webapp/display/text.py @@ -1,6 +1,5 @@ import re - SLUGIFY_PATTERN = re.compile(r"[^a-zA-Z0-9-]") diff --git a/guide/webapp/endpoint/search.py b/guide/webapp/endpoint/search.py index 2bbfc007..030ed24d 100644 --- a/guide/webapp/endpoint/search.py +++ b/guide/webapp/endpoint/search.py @@ -6,7 +6,6 @@ from webapp.display.page import Page from webapp.display.search.renderer import SearchRenderer from webapp.display.search.search import Document, Searcher, Stemmer - bp = Blueprint("search", url_prefix="//search") diff --git a/guide/webapp/endpoint/view.py b/guide/webapp/endpoint/view.py index 220481c6..09f1d04a 100644 --- a/guide/webapp/endpoint/view.py +++ b/guide/webapp/endpoint/view.py @@ -2,5 +2,4 @@ from sanic import Blueprint from .search import bp as search_bp - bp = Blueprint.group(search_bp) diff --git a/guide/webapp/worker/reload.py b/guide/webapp/worker/reload.py index 3269a12d..c3adc24a 100644 --- a/guide/webapp/worker/reload.py +++ b/guide/webapp/worker/reload.py @@ -5,7 +5,6 @@ from queue import Empty, Queue from typing import Any import ujson - from sanic import Request, Sanic, Websocket diff --git a/pyproject.toml b/pyproject.toml index 03d69fa9..23b7a48b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,30 +18,12 @@ ignore = [ "ISC001", "W191", ] -line-length = 79 show-source = true show-fixes = true [tool.ruff.isort] known-first-party = ["sanic"] known-third-party = ["pytest"] -lines-after-imports = 2 -lines-between-types = 1 - -[tool.black] -line-length = 79 - -[tool.isort] -atomic = true -default_section = "THIRDPARTY" -include_trailing_comma = true -known_first_party = "sanic" -known_third_party = "pytest" -line_length = 79 -lines_after_imports = 2 -lines_between_types = 1 -multi_line_output = 3 -profile = "black" [[tool.mypy.overrides]] module = [ diff --git a/sanic/__init__.py b/sanic/__init__.py index 8438ded4..9c0583ec 100644 --- a/sanic/__init__.py +++ b/sanic/__init__.py @@ -36,7 +36,6 @@ from sanic.response import ( ) from sanic.server.websockets.impl import WebsocketImplProtocol as Websocket - DefaultSanic: TypeAlias = "Sanic[Config, SimpleNamespace]" """ A type alias for a Sanic app with a default config and namespace. diff --git a/sanic/__main__.py b/sanic/__main__.py index 7db13563..bc14db89 100644 --- a/sanic/__main__.py +++ b/sanic/__main__.py @@ -1,7 +1,6 @@ from sanic.cli.app import SanicCLI from sanic.compat import OS_IS_WINDOWS, enable_windows_color_support - if OS_IS_WINDOWS: enable_windows_color_support() diff --git a/sanic/app.py b/sanic/app.py index 30c9be8f..f7c22af4 100644 --- a/sanic/app.py +++ b/sanic/app.py @@ -5,7 +5,6 @@ import logging import logging.config import re import sys - from asyncio import ( AbstractEventLoop, CancelledError, @@ -89,7 +88,6 @@ from sanic.worker.inspector import Inspector from sanic.worker.loader import CertLoader from sanic.worker.manager import WorkerManager - if TYPE_CHECKING: try: from sanic_ext import Extend # type: ignore @@ -850,8 +848,8 @@ class Sanic( return if blueprint.name in self.blueprints: assert self.blueprints[blueprint.name] is blueprint, ( - 'A blueprint with the name "{}" is already registered. ' - "Blueprint names must be unique.".format(blueprint.name) + f'A blueprint with the name "{blueprint.name}" is already registered. ' + "Blueprint names must be unique." ) else: self.blueprints[blueprint.name] = blueprint diff --git a/sanic/application/ext.py b/sanic/application/ext.py index 86b482ae..515bc1bc 100644 --- a/sanic/application/ext.py +++ b/sanic/application/ext.py @@ -4,7 +4,6 @@ from contextlib import suppress from importlib import import_module from typing import TYPE_CHECKING - if TYPE_CHECKING: from sanic import Sanic diff --git a/sanic/application/logo.py b/sanic/application/logo.py index 0a2f56a2..c8be7c85 100644 --- a/sanic/application/logo.py +++ b/sanic/application/logo.py @@ -1,11 +1,9 @@ import re import sys - from os import environ from sanic.helpers import is_atty - BASE_LOGO = """ Sanic diff --git a/sanic/application/spinner.py b/sanic/application/spinner.py index ab59f928..f5431072 100644 --- a/sanic/application/spinner.py +++ b/sanic/application/spinner.py @@ -1,12 +1,10 @@ import os import sys import time - from contextlib import contextmanager from queue import Queue from threading import Thread - if os.name == "nt": # noqa import ctypes # noqa diff --git a/sanic/application/state.py b/sanic/application/state.py index 627550e8..435ba226 100644 --- a/sanic/application/state.py +++ b/sanic/application/state.py @@ -1,7 +1,6 @@ from __future__ import annotations import logging - from dataclasses import dataclass, field from pathlib import Path from socket import socket @@ -12,7 +11,6 @@ from sanic.application.constants import Mode, Server, ServerStage from sanic.log import VerbosityFilter, logger from sanic.server.async_server import AsyncioServer - if TYPE_CHECKING: from sanic import Sanic diff --git a/sanic/asgi.py b/sanic/asgi.py index c1578729..fc01f0f7 100644 --- a/sanic/asgi.py +++ b/sanic/asgi.py @@ -1,7 +1,6 @@ from __future__ import annotations import warnings - from typing import TYPE_CHECKING from sanic.compat import Header @@ -15,7 +14,6 @@ from sanic.response import BaseHTTPResponse from sanic.server import ConnInfo from sanic.server.websockets.connection import WebSocketConnection - if TYPE_CHECKING: from sanic import Sanic diff --git a/sanic/base/root.py b/sanic/base/root.py index 3f3ba58e..fc0646fb 100644 --- a/sanic/base/root.py +++ b/sanic/base/root.py @@ -1,5 +1,4 @@ import re - from typing import Any, Optional from sanic.base.meta import SanicMeta @@ -11,7 +10,6 @@ from sanic.mixins.routes import RouteMixin from sanic.mixins.signals import SignalMixin from sanic.mixins.static import StaticMixin - VALID_NAME = re.compile(r"^[a-zA-Z_][a-zA-Z0-9_\-]*$") diff --git a/sanic/blueprint_group.py b/sanic/blueprint_group.py index b95bc520..147aa877 100644 --- a/sanic/blueprint_group.py +++ b/sanic/blueprint_group.py @@ -1,4 +1,3 @@ from .blueprints import BlueprintGroup - __all__ = ["BlueprintGroup"] # noqa: F405 diff --git a/sanic/blueprints.py b/sanic/blueprints.py index 4324d700..2b27ccd1 100644 --- a/sanic/blueprints.py +++ b/sanic/blueprints.py @@ -2,7 +2,6 @@ from __future__ import annotations import asyncio import sys - from collections import defaultdict from collections.abc import MutableSequence from copy import deepcopy @@ -33,7 +32,6 @@ from sanic.models.handler_types import ( RouteHandler, ) - if TYPE_CHECKING: from sanic import Sanic diff --git a/sanic/cli/app.py b/sanic/cli/app.py index cf0dca7f..9c41cd78 100644 --- a/sanic/cli/app.py +++ b/sanic/cli/app.py @@ -1,7 +1,6 @@ import os import shutil import sys - from argparse import Namespace from functools import partial from textwrap import indent diff --git a/sanic/cli/inspector_client.py b/sanic/cli/inspector_client.py index 01c6c14c..7b57cf7e 100644 --- a/sanic/cli/inspector_client.py +++ b/sanic/cli/inspector_client.py @@ -1,7 +1,6 @@ from __future__ import annotations import sys - from http.client import RemoteDisconnected from textwrap import indent from typing import Any @@ -13,7 +12,6 @@ from sanic.application.logo import get_logo from sanic.application.motd import MOTDTTY from sanic.log import Colors - try: # no cov from ujson import dumps, loads except ModuleNotFoundError: # no cov diff --git a/sanic/compat.py b/sanic/compat.py index f64af536..171b4b30 100644 --- a/sanic/compat.py +++ b/sanic/compat.py @@ -3,7 +3,6 @@ import os import platform import signal import sys - from contextlib import contextmanager from enum import Enum from typing import Awaitable, Literal, Union @@ -13,7 +12,6 @@ from multidict import CIMultiDict # type: ignore from sanic.helpers import Default from sanic.log import error_logger - StartMethod = Union[ Default, Literal["fork"], Literal["forkserver"], Literal["spawn"] ] diff --git a/sanic/config.py b/sanic/config.py index d58cbd1d..7a8c0db5 100644 --- a/sanic/config.py +++ b/sanic/config.py @@ -14,7 +14,6 @@ from sanic.http import Http from sanic.log import error_logger from sanic.utils import load_module_from_file_location, str_to_bool - FilterWarningType = Union[ Literal["default"], Literal["error"], diff --git a/sanic/cookies/__init__.py b/sanic/cookies/__init__.py index a5cbe463..5d605d39 100644 --- a/sanic/cookies/__init__.py +++ b/sanic/cookies/__init__.py @@ -1,4 +1,3 @@ from .response import Cookie, CookieJar - __all__ = ("Cookie", "CookieJar") diff --git a/sanic/cookies/request.py b/sanic/cookies/request.py index 456c8872..3cbf430c 100644 --- a/sanic/cookies/request.py +++ b/sanic/cookies/request.py @@ -1,12 +1,10 @@ import re - from typing import Any, Dict, List, Optional from sanic.cookies.response import Cookie from sanic.log import deprecation from sanic.request.parameters import RequestParameters - COOKIE_NAME_RESERVED_CHARS = re.compile( '[\x00-\x1F\x7F-\xFF()<>@,;:\\\\"/[\\]?={} \x09]' ) diff --git a/sanic/cookies/response.py b/sanic/cookies/response.py index ce1ab336..401986ff 100644 --- a/sanic/cookies/response.py +++ b/sanic/cookies/response.py @@ -2,20 +2,17 @@ from __future__ import annotations import re import string - from datetime import datetime from typing import TYPE_CHECKING, Any, Union from sanic.exceptions import ServerError from sanic.log import deprecation - if TYPE_CHECKING: from sanic.compat import Header from typing import Literal - SameSite = Union[ Literal["Strict"], Literal["Lax"], diff --git a/sanic/errorpages.py b/sanic/errorpages.py index 6bfddc87..2a89a8fb 100644 --- a/sanic/errorpages.py +++ b/sanic/errorpages.py @@ -16,7 +16,6 @@ from __future__ import annotations import sys import typing as t - from functools import partial from traceback import extract_tb @@ -26,7 +25,6 @@ from sanic.log import deprecation, logger from sanic.pages.error import ErrorPage from sanic.response import html, json, text - dumps: t.Callable[..., str] try: from ujson import dumps diff --git a/sanic/handlers/__init__.py b/sanic/handlers/__init__.py index 4777a8da..d51d67f9 100644 --- a/sanic/handlers/__init__.py +++ b/sanic/handlers/__init__.py @@ -2,7 +2,6 @@ from .content_range import ContentRangeHandler from .directory import DirectoryHandler from .error import ErrorHandler - __all__ = ( "ContentRangeHandler", "DirectoryHandler", diff --git a/sanic/handlers/content_range.py b/sanic/handlers/content_range.py index 998e90e1..44b92713 100644 --- a/sanic/handlers/content_range.py +++ b/sanic/handlers/content_range.py @@ -1,7 +1,6 @@ from __future__ import annotations import os - from typing import TYPE_CHECKING from sanic.exceptions import ( @@ -11,7 +10,6 @@ from sanic.exceptions import ( ) from sanic.models.protocol_types import Range - if TYPE_CHECKING: from sanic import Request diff --git a/sanic/headers.py b/sanic/headers.py index 892452b9..a52a5907 100644 --- a/sanic/headers.py +++ b/sanic/headers.py @@ -1,14 +1,12 @@ from __future__ import annotations import re - from typing import Any, Dict, Iterable, Tuple, Union from urllib.parse import unquote from sanic.exceptions import InvalidHeader from sanic.helpers import STATUS_CODES - # TODO: # - the Options object should be a typed object to allow for less casting # across the application (in request.py for example) diff --git a/sanic/helpers.py b/sanic/helpers.py index 49424a9c..44077ddc 100644 --- a/sanic/helpers.py +++ b/sanic/helpers.py @@ -1,12 +1,10 @@ """Defines basics of HTTP standard.""" import sys - from importlib import import_module from inspect import ismodule from typing import Dict - STATUS_CODES: Dict[int, bytes] = { 100: b"Continue", 101: b"Switching Protocols", diff --git a/sanic/http/__init__.py b/sanic/http/__init__.py index 10451282..fdf45874 100644 --- a/sanic/http/__init__.py +++ b/sanic/http/__init__.py @@ -2,5 +2,4 @@ from .constants import Stage from .http1 import Http from .http3 import Http3 - __all__ = ("Http", "Stage", "Http3") diff --git a/sanic/http/http1.py b/sanic/http/http1.py index 3384eae6..a994b0d6 100644 --- a/sanic/http/http1.py +++ b/sanic/http/http1.py @@ -2,7 +2,6 @@ from __future__ import annotations from typing import TYPE_CHECKING - if TYPE_CHECKING: from sanic.request import Request from sanic.response import BaseHTTPResponse @@ -25,7 +24,6 @@ from sanic.http.stream import Stream from sanic.log import access_logger, error_logger, logger from sanic.touchup import TouchUpMeta - HTTP_CONTINUE = b"HTTP/1.1 100 Continue\r\n\r\n" diff --git a/sanic/http/http3.py b/sanic/http/http3.py index 9cca6250..b5e60c21 100644 --- a/sanic/http/http3.py +++ b/sanic/http/http3.py @@ -1,7 +1,6 @@ from __future__ import annotations import asyncio - from abc import ABC, abstractmethod from ssl import SSLContext from typing import ( @@ -28,7 +27,6 @@ from sanic.log import Colors, logger from sanic.models.protocol_types import TransportProtocol from sanic.models.server_types import ConnInfo - try: from aioquic.h0.connection import H0_ALPN, H0Connection from aioquic.h3.connection import H3_ALPN, H3Connection diff --git a/sanic/http/stream.py b/sanic/http/stream.py index 3b5b7e00..6fdbaa2e 100644 --- a/sanic/http/stream.py +++ b/sanic/http/stream.py @@ -4,7 +4,6 @@ from typing import TYPE_CHECKING from sanic.http.constants import Stage - if TYPE_CHECKING: from sanic.response import BaseHTTPResponse from sanic.server.protocols.http_protocol import HttpProtocol diff --git a/sanic/http/tls/__init__.py b/sanic/http/tls/__init__.py index b12fe529..ad3e69b9 100644 --- a/sanic/http/tls/__init__.py +++ b/sanic/http/tls/__init__.py @@ -1,5 +1,4 @@ from .context import process_to_context from .creators import get_ssl_context - __all__ = ("get_ssl_context", "process_to_context") diff --git a/sanic/http/tls/context.py b/sanic/http/tls/context.py index 911a634a..1dd12f59 100644 --- a/sanic/http/tls/context.py +++ b/sanic/http/tls/context.py @@ -2,12 +2,10 @@ from __future__ import annotations import os import ssl - from typing import Any, Iterable from sanic.log import logger - # Only allow secure ciphers, notably leaving out AES-CBC mode # OpenSSL chooses ECDSA or RSA depending on the cert in use CIPHERS_TLS12 = [ diff --git a/sanic/http/tls/creators.py b/sanic/http/tls/creators.py index 8ece9c54..9da4aab1 100644 --- a/sanic/http/tls/creators.py +++ b/sanic/http/tls/creators.py @@ -3,7 +3,6 @@ from __future__ import annotations import ssl import subprocess import sys - from abc import ABC, abstractmethod from contextlib import suppress from pathlib import Path @@ -22,7 +21,6 @@ from sanic.exceptions import SanicException from sanic.helpers import Default from sanic.http.tls.context import CertSimple, SanicSSLContext - try: import trustme diff --git a/sanic/log.py b/sanic/log.py index 3bcc7cf6..f65848a4 100644 --- a/sanic/log.py +++ b/sanic/log.py @@ -1,13 +1,11 @@ import logging import sys - from enum import Enum from typing import TYPE_CHECKING, Any, Dict from warnings import warn from sanic.helpers import is_atty - # Python 3.11 changed the way Enum formatting works for mixed-in types. if sys.version_info < (3, 11, 0): diff --git a/sanic/mixins/routes.py b/sanic/mixins/routes.py index bc194db8..dfda51e2 100644 --- a/sanic/mixins/routes.py +++ b/sanic/mixins/routes.py @@ -25,7 +25,6 @@ from sanic.models.futures import FutureRoute, FutureStatic from sanic.models.handler_types import RouteHandler from sanic.types import HashableDict - RouteWrapper = Callable[ [RouteHandler], Union[RouteHandler, Tuple[Route, RouteHandler]] ] diff --git a/sanic/mixins/startup.py b/sanic/mixins/startup.py index b743b827..16ce3637 100644 --- a/sanic/mixins/startup.py +++ b/sanic/mixins/startup.py @@ -2,7 +2,6 @@ from __future__ import annotations import os import platform - from asyncio import ( AbstractEventLoop, CancelledError, @@ -64,7 +63,6 @@ from sanic.worker.multiplexer import WorkerMultiplexer from sanic.worker.reloader import Reloader from sanic.worker.serve import worker_serve - if TYPE_CHECKING: from sanic import Sanic from sanic.application.state import ApplicationState @@ -74,7 +72,6 @@ SANIC_PACKAGES = ("sanic-routing", "sanic-testing", "sanic-ext") from typing import Literal - HTTPVersion = Union[HTTP, Literal[1], Literal[3]] diff --git a/sanic/models/asgi.py b/sanic/models/asgi.py index 074f39bc..de2cfd3f 100644 --- a/sanic/models/asgi.py +++ b/sanic/models/asgi.py @@ -1,12 +1,10 @@ import asyncio - from typing import Any, Awaitable, Callable, MutableMapping, Optional, Union from sanic.exceptions import BadRequest from sanic.models.protocol_types import TransportProtocol from sanic.server.websockets.connection import WebSocketConnection - ASGIScope = MutableMapping[str, Any] ASGIMessage = MutableMapping[str, Any] ASGISend = Callable[[ASGIMessage], Awaitable[None]] diff --git a/sanic/models/handler_types.py b/sanic/models/handler_types.py index 7d123d0b..d2bb205e 100644 --- a/sanic/models/handler_types.py +++ b/sanic/models/handler_types.py @@ -2,11 +2,9 @@ from asyncio.events import AbstractEventLoop from typing import Any, Callable, Coroutine, Optional, TypeVar, Union import sanic - from sanic import request from sanic.response import BaseHTTPResponse, HTTPResponse - Sanic = TypeVar("Sanic", bound="sanic.Sanic") Request = TypeVar("Request", bound="request.Request") diff --git a/sanic/models/protocol_types.py b/sanic/models/protocol_types.py index f25737c9..e2c70c4d 100644 --- a/sanic/models/protocol_types.py +++ b/sanic/models/protocol_types.py @@ -3,7 +3,6 @@ from __future__ import annotations from asyncio import BaseTransport from typing import TYPE_CHECKING, AnyStr - if TYPE_CHECKING: from sanic.http.constants import HTTP from sanic.models.asgi import ASGIScope diff --git a/sanic/pages/css.py b/sanic/pages/css.py index 8852d31a..9dfa5338 100644 --- a/sanic/pages/css.py +++ b/sanic/pages/css.py @@ -2,7 +2,6 @@ from abc import ABCMeta from pathlib import Path from typing import Optional - CURRENT_DIR = Path(__file__).parent diff --git a/sanic/pages/error.py b/sanic/pages/error.py index 11580db4..33f52a9d 100644 --- a/sanic/pages/error.py +++ b/sanic/pages/error.py @@ -1,7 +1,6 @@ from typing import Any, Mapping import tracerite.html - from html5tagger import E from tracerite import html_traceback, inspector @@ -9,7 +8,6 @@ from sanic.request import Request from .base import BasePage - # Avoid showing the request in the traceback variable inspectors inspector.blacklist_types += (Request,) diff --git a/sanic/request/__init__.py b/sanic/request/__init__.py index 3321f234..37037937 100644 --- a/sanic/request/__init__.py +++ b/sanic/request/__init__.py @@ -2,7 +2,6 @@ from .form import File, parse_multipart_form from .parameters import RequestParameters from .types import Request - __all__ = ( "File", "parse_multipart_form", diff --git a/sanic/request/form.py b/sanic/request/form.py index 3f3a4166..18c97205 100644 --- a/sanic/request/form.py +++ b/sanic/request/form.py @@ -2,7 +2,6 @@ from __future__ import annotations import email.utils import unicodedata - from typing import NamedTuple from urllib.parse import unquote diff --git a/sanic/request/types.py b/sanic/request/types.py index 59b7b3f5..67eb47b7 100644 --- a/sanic/request/types.py +++ b/sanic/request/types.py @@ -19,14 +19,12 @@ from sanic.http.stream import Stream from sanic.models.asgi import ASGIScope from sanic.models.http_types import Credentials - if TYPE_CHECKING: from sanic.app import Sanic from sanic.config import Config from sanic.server import ConnInfo import uuid - from collections import defaultdict from urllib.parse import parse_qs, parse_qsl, urlunparse @@ -60,7 +58,6 @@ from sanic.response import BaseHTTPResponse, HTTPResponse from .form import parse_multipart_form from .parameters import RequestParameters - try: from ujson import loads as json_loads # type: ignore except ImportError: diff --git a/sanic/response/__init__.py b/sanic/response/__init__.py index 99b93075..2a597cab 100644 --- a/sanic/response/__init__.py +++ b/sanic/response/__init__.py @@ -17,7 +17,6 @@ from .types import ( json_dumps, ) - __all__ = ( "BaseHTTPResponse", "HTTPResponse", diff --git a/sanic/response/types.py b/sanic/response/types.py index 21de0c4e..c96ba173 100644 --- a/sanic/response/types.py +++ b/sanic/response/types.py @@ -24,7 +24,6 @@ from sanic.helpers import ( ) from sanic.http import Http - if TYPE_CHECKING: from sanic.asgi import ASGIApp from sanic.http.http3 import HTTPReceiver diff --git a/sanic/router.py b/sanic/router.py index dedcf1e9..0f016c64 100644 --- a/sanic/router.py +++ b/sanic/router.py @@ -15,7 +15,6 @@ from sanic.errorpages import check_error_format from sanic.exceptions import MethodNotAllowed, NotFound, SanicException from sanic.models.handler_types import RouteHandler - ROUTER_CACHE_SIZE = 1024 ALLOWED_LABELS = ("__file_uri__",) diff --git a/sanic/server/__init__.py b/sanic/server/__init__.py index a6b1a98c..5ae81909 100644 --- a/sanic/server/__init__.py +++ b/sanic/server/__init__.py @@ -4,7 +4,6 @@ from sanic.server.loop import try_use_uvloop from sanic.server.protocols.http_protocol import HttpProtocol from sanic.server.runners import serve - __all__ = ( "AsyncioServer", "ConnInfo", diff --git a/sanic/server/async_server.py b/sanic/server/async_server.py index 754a6e4e..4796d5a9 100644 --- a/sanic/server/async_server.py +++ b/sanic/server/async_server.py @@ -1,12 +1,10 @@ from __future__ import annotations import asyncio - from typing import TYPE_CHECKING from sanic.exceptions import SanicException - if TYPE_CHECKING: from sanic import Sanic diff --git a/sanic/server/events.py b/sanic/server/events.py index d10d3591..cacab407 100644 --- a/sanic/server/events.py +++ b/sanic/server/events.py @@ -3,7 +3,6 @@ from __future__ import annotations from inspect import isawaitable from typing import TYPE_CHECKING, Any, Callable, Iterable - if TYPE_CHECKING: from sanic import Sanic diff --git a/sanic/server/loop.py b/sanic/server/loop.py index 97cd8fdf..6fbc04e4 100644 --- a/sanic/server/loop.py +++ b/sanic/server/loop.py @@ -1,6 +1,5 @@ import asyncio import sys - from os import getenv from sanic.compat import OS_IS_WINDOWS diff --git a/sanic/server/protocols/base_protocol.py b/sanic/server/protocols/base_protocol.py index 709eea9e..8678f471 100644 --- a/sanic/server/protocols/base_protocol.py +++ b/sanic/server/protocols/base_protocol.py @@ -4,12 +4,10 @@ from typing import TYPE_CHECKING from sanic.exceptions import RequestCancelled - if TYPE_CHECKING: from sanic.app import Sanic import asyncio - from asyncio.transports import Transport from time import monotonic as current_time diff --git a/sanic/server/protocols/http_protocol.py b/sanic/server/protocols/http_protocol.py index 315912f1..f63d61dd 100644 --- a/sanic/server/protocols/http_protocol.py +++ b/sanic/server/protocols/http_protocol.py @@ -6,12 +6,10 @@ from sanic.http.constants import HTTP from sanic.http.http3 import Http3 from sanic.touchup.meta import TouchUpMeta - if TYPE_CHECKING: from sanic.app import Sanic import sys - from asyncio import CancelledError from time import monotonic as current_time @@ -26,7 +24,6 @@ from sanic.models.server_types import ConnInfo from sanic.request import Request from sanic.server.protocols.base_protocol import SanicProtocol - ConnectionProtocol = type("ConnectionProtocol", (), {}) try: from aioquic.asyncio import QuicConnectionProtocol diff --git a/sanic/server/protocols/websocket_protocol.py b/sanic/server/protocols/websocket_protocol.py index 475f7981..f137e0fa 100644 --- a/sanic/server/protocols/websocket_protocol.py +++ b/sanic/server/protocols/websocket_protocol.py @@ -1,6 +1,5 @@ from typing import TYPE_CHECKING, Optional, Sequence, cast - try: # websockets < 11.0 from websockets.connection import State from websockets.server import ServerConnection as ServerProtocol @@ -16,7 +15,6 @@ from sanic.server import HttpProtocol from ..websockets.impl import WebsocketImplProtocol - if TYPE_CHECKING: from websockets import http11 diff --git a/sanic/server/runners.py b/sanic/server/runners.py index de3d4139..fc361d8f 100644 --- a/sanic/server/runners.py +++ b/sanic/server/runners.py @@ -8,14 +8,12 @@ from sanic.exceptions import ServerError from sanic.http.constants import HTTP from sanic.http.tls import get_ssl_context - if TYPE_CHECKING: from sanic.app import Sanic import asyncio import os import socket - from functools import partial from signal import SIG_IGN, SIGINT, SIGTERM from signal import signal as signal_func @@ -29,7 +27,6 @@ from sanic.server.async_server import AsyncioServer from sanic.server.protocols.http_protocol import Http3Protocol, HttpProtocol from sanic.server.socket import bind_unix_socket, remove_unix_socket - try: from aioquic.asyncio import serve as quic_serve diff --git a/sanic/server/socket.py b/sanic/server/socket.py index 31d0bbdc..2a77a1c6 100644 --- a/sanic/server/socket.py +++ b/sanic/server/socket.py @@ -4,7 +4,6 @@ import os import secrets import socket import stat - from ipaddress import ip_address from typing import Any diff --git a/sanic/server/websockets/connection.py b/sanic/server/websockets/connection.py index 8ff19da6..41176694 100644 --- a/sanic/server/websockets/connection.py +++ b/sanic/server/websockets/connection.py @@ -11,7 +11,6 @@ from typing import ( from sanic.exceptions import InvalidUsage - ASGIMessage = MutableMapping[str, Any] diff --git a/sanic/server/websockets/frame.py b/sanic/server/websockets/frame.py index cb63b7c3..0b8aa0fa 100644 --- a/sanic/server/websockets/frame.py +++ b/sanic/server/websockets/frame.py @@ -1,6 +1,5 @@ import asyncio import codecs - from typing import TYPE_CHECKING, AsyncIterator, List, Optional from websockets.frames import Frame, Opcode @@ -8,7 +7,6 @@ from websockets.typing import Data from sanic.exceptions import ServerError - if TYPE_CHECKING: from .impl import WebsocketImplProtocol diff --git a/sanic/server/websockets/impl.py b/sanic/server/websockets/impl.py index e08a41b7..c0eeb80f 100644 --- a/sanic/server/websockets/impl.py +++ b/sanic/server/websockets/impl.py @@ -1,7 +1,6 @@ import asyncio import random import struct - from typing import ( AsyncIterator, Dict, @@ -19,7 +18,6 @@ from websockets.exceptions import ( ) from websockets.frames import Frame, Opcode - try: # websockets < 11.0 from websockets.connection import Event, State # type: ignore from websockets.server import ServerConnection as ServerProtocol @@ -35,7 +33,6 @@ from sanic.server.protocols.base_protocol import SanicProtocol from ...exceptions import ServerError, WebsocketClosed from .frame import WebsocketFrameAssembler - OPEN = State.OPEN CLOSING = State.CLOSING CLOSED = State.CLOSED diff --git a/sanic/signals.py b/sanic/signals.py index 740640a8..9fea88cf 100644 --- a/sanic/signals.py +++ b/sanic/signals.py @@ -1,7 +1,6 @@ from __future__ import annotations import asyncio - from enum import Enum from inspect import isawaitable from typing import Any, cast diff --git a/sanic/touchup/__init__.py b/sanic/touchup/__init__.py index 6fe208ab..4b2d73eb 100644 --- a/sanic/touchup/__init__.py +++ b/sanic/touchup/__init__.py @@ -1,7 +1,6 @@ from .meta import TouchUpMeta from .service import TouchUp - __all__ = ( "TouchUp", "TouchUpMeta", diff --git a/sanic/touchup/schemes/altsvc.py b/sanic/touchup/schemes/altsvc.py index 8f88cf90..8fce4c35 100644 --- a/sanic/touchup/schemes/altsvc.py +++ b/sanic/touchup/schemes/altsvc.py @@ -7,7 +7,6 @@ from sanic.http.constants import HTTP from .base import BaseScheme - if TYPE_CHECKING: from sanic import Sanic diff --git a/sanic/types/__init__.py b/sanic/types/__init__.py index 043fffb4..feb53ab5 100644 --- a/sanic/types/__init__.py +++ b/sanic/types/__init__.py @@ -1,4 +1,3 @@ from .hashable_dict import HashableDict - __all__ = ("HashableDict",) diff --git a/sanic/types/shared_ctx.py b/sanic/types/shared_ctx.py index e0c069b2..bf95ee65 100644 --- a/sanic/types/shared_ctx.py +++ b/sanic/types/shared_ctx.py @@ -1,5 +1,4 @@ import os - from types import SimpleNamespace from typing import Any, Iterable diff --git a/sanic/utils.py b/sanic/utils.py index 83538f7d..0ec9e5d2 100644 --- a/sanic/utils.py +++ b/sanic/utils.py @@ -1,5 +1,4 @@ import types - from importlib.util import module_from_spec, spec_from_file_location from os import environ as os_environ from pathlib import Path diff --git a/sanic/views.py b/sanic/views.py index 6226aec4..93e25401 100644 --- a/sanic/views.py +++ b/sanic/views.py @@ -10,7 +10,6 @@ from typing import ( from sanic.models.handler_types import RouteHandler from sanic.request.types import Request - if TYPE_CHECKING: from sanic import Sanic from sanic.blueprints import Blueprint diff --git a/sanic/worker/loader.py b/sanic/worker/loader.py index 48f4e62a..944346ba 100644 --- a/sanic/worker/loader.py +++ b/sanic/worker/loader.py @@ -2,7 +2,6 @@ from __future__ import annotations import os import sys - from contextlib import suppress from importlib import import_module from inspect import isfunction @@ -13,7 +12,6 @@ from typing import TYPE_CHECKING, Any, Callable, cast from sanic.http.tls.context import process_to_context from sanic.http.tls.creators import MkcertCreator, TrustmeCreator - if TYPE_CHECKING: from sanic import Sanic as SanicApp diff --git a/sanic/worker/manager.py b/sanic/worker/manager.py index ae242cd4..ff85fd81 100644 --- a/sanic/worker/manager.py +++ b/sanic/worker/manager.py @@ -1,5 +1,4 @@ import os - from contextlib import suppress from itertools import count from random import choice @@ -13,7 +12,6 @@ from sanic.log import error_logger, logger from sanic.worker.constants import RestartOrder from sanic.worker.process import ProcessState, Worker, WorkerProcess - if not OS_IS_WINDOWS: from signal import SIGKILL else: diff --git a/sanic/worker/process.py b/sanic/worker/process.py index 83b3556b..9bf0df42 100644 --- a/sanic/worker/process.py +++ b/sanic/worker/process.py @@ -1,5 +1,4 @@ import os - from datetime import datetime, timezone from multiprocessing.context import BaseContext from signal import SIGINT diff --git a/sanic/worker/reloader.py b/sanic/worker/reloader.py index f8c5ab84..ef7c50dd 100644 --- a/sanic/worker/reloader.py +++ b/sanic/worker/reloader.py @@ -2,7 +2,6 @@ from __future__ import annotations import os import sys - from asyncio import new_event_loop from itertools import chain from multiprocessing.connection import Connection diff --git a/sanic/worker/serve.py b/sanic/worker/serve.py index 583d3eaf..d808c95b 100644 --- a/sanic/worker/serve.py +++ b/sanic/worker/serve.py @@ -2,7 +2,6 @@ import asyncio import os import socket import warnings - from functools import partial from multiprocessing.connection import Connection from ssl import SSLContext diff --git a/sanic/worker/state.py b/sanic/worker/state.py index 1155745e..07103a5d 100644 --- a/sanic/worker/state.py +++ b/sanic/worker/state.py @@ -2,7 +2,6 @@ from collections.abc import Mapping from typing import Any, Dict, ItemsView, Iterator, KeysView, List, ValuesView from typing import Mapping as MappingType - dict diff --git a/scripts/changelog.py b/scripts/changelog.py index 091fb38f..97df43ba 100755 --- a/scripts/changelog.py +++ b/scripts/changelog.py @@ -1,10 +1,8 @@ #!/usr/bin/env python import sys - from os import path - if __name__ == "__main__": try: import click diff --git a/scripts/release.py b/scripts/release.py index b0158485..0d920bdb 100755 --- a/scripts/release.py +++ b/scripts/release.py @@ -1,7 +1,6 @@ #!/usr/bin/env python import sys - from argparse import ArgumentParser, Namespace from collections import OrderedDict from configparser import RawConfigParser @@ -11,11 +10,9 @@ from os import chdir, path from subprocess import PIPE, Popen import towncrier - from jinja2 import BaseLoader, Environment from requests import patch - GIT_COMMANDS = { "get_tag": ["git describe --tags --abbrev=0"], "commit_version_change": [ @@ -256,9 +253,7 @@ def release(args: Namespace): if current_tag and current_version not in current_tag: print( "Tag mismatch between what's in git and what was provided by " - "--current-version. Existing: {}, Give: {}".format( - current_tag, current_version - ) + f"--current-version. Existing: {current_tag}, Give: {current_version}" ) sys.exit(1) new_version = args.release_version or _get_new_version( diff --git a/setup.py b/setup.py index fb817e24..7b91d284 100644 --- a/setup.py +++ b/setup.py @@ -123,9 +123,7 @@ tests_require = [ "pytest-sanic", "pytest-benchmark", "chardet==3.*", - "flake8", - "black", - "isort>=5.0.0", + "ruff", "bandit", "mypy", "docutils", diff --git a/tests/benchmark/test_route_resolution_benchmark.py b/tests/benchmark/test_route_resolution_benchmark.py index 0a416474..8405f4a0 100644 --- a/tests/benchmark/test_route_resolution_benchmark.py +++ b/tests/benchmark/test_route_resolution_benchmark.py @@ -3,10 +3,8 @@ from random import choice, seed from pytest import mark import sanic.router - from sanic.request import Request - seed("Pack my box with five dozen liquor jugs.") # Disable Caching for testing purpose diff --git a/tests/client.py b/tests/client.py index 4c0b29a0..6a9f3e6e 100644 --- a/tests/client.py +++ b/tests/client.py @@ -1,5 +1,4 @@ import asyncio - from textwrap import dedent from typing import AnyStr diff --git a/tests/conftest.py b/tests/conftest.py index 0e94a0d2..c6523797 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -7,14 +7,12 @@ import re import string import sys import uuid - from contextlib import suppress from logging import LogRecord from typing import Any, Dict, List, Tuple from unittest.mock import MagicMock, Mock, patch import pytest - from sanic_routing.exceptions import RouteExists from sanic_testing.testing import PORT @@ -23,7 +21,6 @@ from sanic.constants import HTTP_METHODS from sanic.router import Router from sanic.touchup.service import TouchUp - slugify = re.compile(r"[^a-zA-Z0-9_\-]") random.seed("Pack my box with five dozen liquor jugs.") Sanic.test_mode = True diff --git a/tests/fake/server.py b/tests/fake/server.py index 577b70bf..b38654a0 100644 --- a/tests/fake/server.py +++ b/tests/fake/server.py @@ -5,7 +5,6 @@ from sanic.application.constants import Mode from sanic.config import Config from sanic.log import LOGGING_CONFIG_DEFAULTS, logger - LOGGING_CONFIG = {**LOGGING_CONFIG_DEFAULTS} LOGGING_CONFIG["formatters"]["generic"]["format"] = "%(message)s" LOGGING_CONFIG["loggers"]["sanic.root"]["level"] = "DEBUG" diff --git a/tests/http3/test_http_receiver.py b/tests/http3/test_http_receiver.py index d996c484..0bed7241 100644 --- a/tests/http3/test_http_receiver.py +++ b/tests/http3/test_http_receiver.py @@ -1,7 +1,6 @@ from unittest.mock import Mock import pytest - from aioquic.h3.connection import H3Connection from aioquic.h3.events import DataReceived, HeadersReceived from aioquic.quic.configuration import QuicConfiguration @@ -18,7 +17,6 @@ from sanic.models.server_types import ConnInfo from sanic.response import empty, json from sanic.server.protocols.http_protocol import Http3Protocol - try: from unittest.mock import AsyncMock except ImportError: diff --git a/tests/http3/test_server.py b/tests/http3/test_server.py index 20b45b6d..04836c19 100644 --- a/tests/http3/test_server.py +++ b/tests/http3/test_server.py @@ -1,6 +1,5 @@ import logging import sys - from asyncio import Event from pathlib import Path @@ -10,7 +9,6 @@ from sanic import Sanic from sanic.compat import UVLOOP_INSTALLED from sanic.http.constants import HTTP - parent_dir = Path(__file__).parent.parent localhost_dir = parent_dir / "certs/localhost" diff --git a/tests/performance/aiohttp/simple_server.py b/tests/performance/aiohttp/simple_server.py index 9a57f459..fe076e15 100644 --- a/tests/performance/aiohttp/simple_server.py +++ b/tests/performance/aiohttp/simple_server.py @@ -5,10 +5,8 @@ import sys import ujson as json import uvloop - from aiohttp import web - loop = uvloop.new_event_loop() asyncio.set_event_loop(loop) diff --git a/tests/performance/bottle/simple_server.py b/tests/performance/bottle/simple_server.py index 97846572..5857469b 100644 --- a/tests/performance/bottle/simple_server.py +++ b/tests/performance/bottle/simple_server.py @@ -1,7 +1,6 @@ # Run with: gunicorn --workers=1 --worker-class=meinheld.gmeinheld.MeinheldWorker -b :8000 simple_server:app import bottle import ujson - from bottle import route diff --git a/tests/performance/kyoukai/simple_server.py b/tests/performance/kyoukai/simple_server.py index 9fd7d2b0..e6a28650 100644 --- a/tests/performance/kyoukai/simple_server.py +++ b/tests/performance/kyoukai/simple_server.py @@ -4,10 +4,8 @@ import logging import ujson import uvloop - from kyoukai import HTTPRequestContext, Kyoukai - loop = uvloop.new_event_loop() asyncio.set_event_loop(loop) diff --git a/tests/performance/sanic/http_response.py b/tests/performance/sanic/http_response.py index 6352b8fd..6e845e79 100644 --- a/tests/performance/sanic/http_response.py +++ b/tests/performance/sanic/http_response.py @@ -5,7 +5,6 @@ import timeit from sanic.response import json - currentdir = os.path.dirname( os.path.abspath(inspect.getfile(inspect.currentframe())) ) diff --git a/tests/performance/sanic/simple_server.py b/tests/performance/sanic/simple_server.py index 60ebd819..976c47c1 100644 --- a/tests/performance/sanic/simple_server.py +++ b/tests/performance/sanic/simple_server.py @@ -5,7 +5,6 @@ import sys from sanic import Sanic from sanic.response import json - currentdir = os.path.dirname( os.path.abspath(inspect.getfile(inspect.currentframe())) ) diff --git a/tests/performance/sanic/varied_server.py b/tests/performance/sanic/varied_server.py index 13d26d20..fa6a8084 100644 --- a/tests/performance/sanic/varied_server.py +++ b/tests/performance/sanic/varied_server.py @@ -6,7 +6,6 @@ from sanic import Sanic from sanic.exceptions import ServerError from sanic.response import json, text - currentdir = os.path.dirname( os.path.abspath(inspect.getfile(inspect.currentframe())) ) diff --git a/tests/performance/tornado/simple_server.py b/tests/performance/tornado/simple_server.py index 1e69a293..a326eeaf 100644 --- a/tests/performance/tornado/simple_server.py +++ b/tests/performance/tornado/simple_server.py @@ -1,6 +1,5 @@ # Run with: python simple_server.py import ujson - from tornado import ioloop, web diff --git a/tests/performance/wheezy/simple_server.py b/tests/performance/wheezy/simple_server.py index 56d4ca63..d892d342 100644 --- a/tests/performance/wheezy/simple_server.py +++ b/tests/performance/wheezy/simple_server.py @@ -2,7 +2,6 @@ """ Minimal helloworld application. """ import ujson - from wheezy.http import HTTPResponse, WSGIApplication from wheezy.routing import url from wheezy.web.handlers import BaseHandler @@ -37,7 +36,6 @@ main = WSGIApplication( if __name__ == "__main__": import sys - from wsgiref.simple_server import make_server try: diff --git a/tests/test_app.py b/tests/test_app.py index ed112d52..575428cc 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -1,7 +1,6 @@ import asyncio import logging import re - from collections import Counter from inspect import isawaitable from os import environ @@ -10,7 +9,6 @@ from unittest.mock import Mock, patch import pytest import sanic - from sanic import Sanic from sanic.compat import OS_IS_WINDOWS from sanic.config import Config diff --git a/tests/test_asgi.py b/tests/test_asgi.py index f5de8fdc..111d7e12 100644 --- a/tests/test_asgi.py +++ b/tests/test_asgi.py @@ -1,11 +1,9 @@ import logging - from collections import deque, namedtuple from unittest.mock import call import pytest import uvicorn - from httpx import Headers from pytest import MonkeyPatch @@ -18,7 +16,6 @@ from sanic.response import json, text from sanic.server.websockets.connection import WebSocketConnection from sanic.signals import RESERVED_NAMESPACES - try: from unittest.mock import AsyncMock except ImportError: diff --git a/tests/test_blueprint_copy.py b/tests/test_blueprint_copy.py index 5dd742ea..091a9532 100644 --- a/tests/test_blueprint_copy.py +++ b/tests/test_blueprint_copy.py @@ -1,5 +1,4 @@ import pytest - from sanic_routing.exceptions import RouteExists from sanic import Blueprint, Request, Sanic diff --git a/tests/test_blueprint_group.py b/tests/test_blueprint_group.py index f36d5ee9..06472af4 100644 --- a/tests/test_blueprint_group.py +++ b/tests/test_blueprint_group.py @@ -1,5 +1,4 @@ import pytest - from pytest import raises from sanic.app import Sanic @@ -9,7 +8,6 @@ from sanic.exceptions import BadRequest, Forbidden, SanicException, ServerError from sanic.request import Request from sanic.response import HTTPResponse, text - MIDDLEWARE_INVOKE_COUNTER = {"request": 0, "response": 0} AUTH = "dGVzdDp0ZXN0Cg==" diff --git a/tests/test_blueprints.py b/tests/test_blueprints.py index cf4167c7..3bfc4386 100644 --- a/tests/test_blueprints.py +++ b/tests/test_blueprints.py @@ -11,7 +11,6 @@ from sanic.exceptions import BadRequest, NotFound, SanicException, ServerError from sanic.request import Request from sanic.response import json, text - # ------------------------------------------------------------ # # GET # ------------------------------------------------------------ # diff --git a/tests/test_cli.py b/tests/test_cli.py index 2e980a2c..d327aa1b 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,13 +1,11 @@ import json import os import sys - from pathlib import Path from typing import List, Optional, Tuple from unittest.mock import patch import pytest - from sanic_routing import __version__ as __routing_version__ from sanic import __version__ diff --git a/tests/test_coffee.py b/tests/test_coffee.py index 43864b3d..73237ff0 100644 --- a/tests/test_coffee.py +++ b/tests/test_coffee.py @@ -1,5 +1,4 @@ import logging - from unittest.mock import patch import pytest diff --git a/tests/test_config.py b/tests/test_config.py index a702bc88..17bd488e 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -1,6 +1,5 @@ import logging import os - from contextlib import contextmanager from os import environ from pathlib import Path @@ -9,7 +8,6 @@ from textwrap import dedent from unittest.mock import Mock, call import pytest - from pytest import MonkeyPatch from sanic import Sanic diff --git a/tests/test_cookies.py b/tests/test_cookies.py index 547cdd42..544300ac 100644 --- a/tests/test_cookies.py +++ b/tests/test_cookies.py @@ -12,7 +12,6 @@ from sanic.exceptions import ServerError from sanic.response import text from sanic.response.convenience import json - # ------------------------------------------------------------ # # GET # ------------------------------------------------------------ # diff --git a/tests/test_create_task.py b/tests/test_create_task.py index 946c7aaa..cdd9f711 100644 --- a/tests/test_create_task.py +++ b/tests/test_create_task.py @@ -1,6 +1,5 @@ import asyncio import sys - from threading import Event import pytest diff --git a/tests/test_dynamic_routes.py b/tests/test_dynamic_routes.py index 0147f755..6a3cfa37 100644 --- a/tests/test_dynamic_routes.py +++ b/tests/test_dynamic_routes.py @@ -1,5 +1,4 @@ import pytest - from sanic_routing.exceptions import RouteExists from sanic.response import text diff --git a/tests/test_errorpages.py b/tests/test_errorpages.py index 2ef5679b..440677c9 100644 --- a/tests/test_errorpages.py +++ b/tests/test_errorpages.py @@ -3,7 +3,6 @@ import logging import pytest import sanic - from sanic import Sanic from sanic.config import Config from sanic.errorpages import TextRenderer, exception_response, guess_mime diff --git a/tests/test_exceptions.py b/tests/test_exceptions.py index 0151c2e8..0fec0079 100644 --- a/tests/test_exceptions.py +++ b/tests/test_exceptions.py @@ -1,7 +1,6 @@ import logging import pytest - from bs4 import BeautifulSoup from sanic import Sanic diff --git a/tests/test_exceptions_handler.py b/tests/test_exceptions_handler.py index a5cb597c..ed2621eb 100644 --- a/tests/test_exceptions_handler.py +++ b/tests/test_exceptions_handler.py @@ -1,11 +1,9 @@ import asyncio import logging - from typing import Callable, List from unittest.mock import Mock import pytest - from bs4 import BeautifulSoup from pytest import LogCaptureFixture, MonkeyPatch diff --git a/tests/test_ext_integration.py b/tests/test_ext_integration.py index 19c50807..a837ee12 100644 --- a/tests/test_ext_integration.py +++ b/tests/test_ext_integration.py @@ -4,7 +4,6 @@ import pytest from sanic import Sanic - try: import sanic_ext # noqa: F401 diff --git a/tests/test_graceful_shutdown.py b/tests/test_graceful_shutdown.py index d125ba3d..9befbba4 100644 --- a/tests/test_graceful_shutdown.py +++ b/tests/test_graceful_shutdown.py @@ -5,7 +5,6 @@ from pytest import LogCaptureFixture from sanic.response import empty - PORT = 42101 diff --git a/tests/test_http.py b/tests/test_http.py index ca2e86c0..11554663 100644 --- a/tests/test_http.py +++ b/tests/test_http.py @@ -1,18 +1,15 @@ import json as stdjson - from collections import namedtuple from pathlib import Path from sys import version_info import pytest - from sanic_testing.reusable import ReusableClient from sanic import json, text from sanic.app import Sanic from tests.client import RawClient - parent_dir = Path(__file__).parent localhost_dir = parent_dir / "certs/localhost" diff --git a/tests/test_http_alt_svc.py b/tests/test_http_alt_svc.py index 1184a8dd..a7c74a77 100644 --- a/tests/test_http_alt_svc.py +++ b/tests/test_http_alt_svc.py @@ -1,5 +1,4 @@ import sys - from pathlib import Path import pytest @@ -8,7 +7,6 @@ from sanic.app import Sanic from sanic.response import empty from tests.client import RawClient - parent_dir = Path(__file__).parent localhost_dir = parent_dir / "certs/localhost" diff --git a/tests/test_json_decoding.py b/tests/test_json_decoding.py index 57fdbc6b..0c871a4c 100644 --- a/tests/test_json_decoding.py +++ b/tests/test_json_decoding.py @@ -2,7 +2,6 @@ from json import loads as sloads import pytest - try: from ujson import loads as uloads diff --git a/tests/test_json_encoding.py b/tests/test_json_encoding.py index f581b3e3..1dedbf72 100644 --- a/tests/test_json_encoding.py +++ b/tests/test_json_encoding.py @@ -1,5 +1,4 @@ import sys - from dataclasses import asdict, dataclass from functools import partial from json import dumps as sdumps @@ -8,10 +7,8 @@ from typing import Dict import pytest - try: import ujson - from ujson import dumps as udumps ujson_version = tuple( diff --git a/tests/test_keep_alive_timeout.py b/tests/test_keep_alive_timeout.py index a69ae49b..cfa9f009 100644 --- a/tests/test_keep_alive_timeout.py +++ b/tests/test_keep_alive_timeout.py @@ -1,19 +1,16 @@ import asyncio import platform - from asyncio import sleep as aio_sleep from itertools import count from os import environ import pytest - from sanic_testing.reusable import ReusableClient from sanic import Sanic from sanic.compat import OS_IS_WINDOWS from sanic.response import text - CONFIG_FOR_TESTS = {"KEEP_ALIVE_TIMEOUT": 2, "KEEP_ALIVE": True} PORT = 42001 # test_keep_alive_timeout_reuse doesn't work with random port diff --git a/tests/test_logging.py b/tests/test_logging.py index 3a7ba4f5..e099c998 100644 --- a/tests/test_logging.py +++ b/tests/test_logging.py @@ -1,6 +1,5 @@ import logging import uuid - from importlib import reload from io import StringIO from unittest.mock import Mock @@ -8,12 +7,10 @@ from unittest.mock import Mock import pytest import sanic - from sanic import Sanic from sanic.log import LOGGING_CONFIG_DEFAULTS, Colors, logger from sanic.response import text - logging_format = """module: %(module)s; \ function: %(funcName)s(); \ message: %(message)s""" diff --git a/tests/test_logo.py b/tests/test_logo.py index 9f3eea2a..72837277 100644 --- a/tests/test_logo.py +++ b/tests/test_logo.py @@ -1,6 +1,5 @@ import os import sys - from unittest.mock import patch import pytest diff --git a/tests/test_middleware.py b/tests/test_middleware.py index 6589f4a4..85336ad9 100644 --- a/tests/test_middleware.py +++ b/tests/test_middleware.py @@ -1,5 +1,4 @@ import logging - from asyncio import CancelledError, sleep from itertools import count @@ -7,7 +6,6 @@ from sanic.exceptions import NotFound from sanic.request import Request from sanic.response import HTTPResponse, json, text - # ------------------------------------------------------------ # # GET # ------------------------------------------------------------ # diff --git a/tests/test_middleware_priority.py b/tests/test_middleware_priority.py index c16f658b..abb0189f 100644 --- a/tests/test_middleware_priority.py +++ b/tests/test_middleware_priority.py @@ -6,7 +6,6 @@ from sanic import Sanic from sanic.middleware import Middleware, MiddlewareLocation from sanic.response import json - PRIORITY_TEST_CASES = ( ([0, 1, 2], [1, 1, 1]), ([0, 1, 2], [1, 1, None]), diff --git a/tests/test_motd.py b/tests/test_motd.py index 2e9eeab7..9b5c1af1 100644 --- a/tests/test_motd.py +++ b/tests/test_motd.py @@ -2,7 +2,6 @@ import logging import os import platform import sys - from unittest.mock import Mock, patch import pytest diff --git a/tests/test_multiprocessing.py b/tests/test_multiprocessing.py index 98e19073..64cfea0b 100644 --- a/tests/test_multiprocessing.py +++ b/tests/test_multiprocessing.py @@ -4,11 +4,9 @@ import pickle import random import signal import sys - from asyncio import sleep import pytest - from sanic_testing.testing import HOST, PORT from sanic import Blueprint, text diff --git a/tests/test_named_routes.py b/tests/test_named_routes.py index acad0e37..30302521 100644 --- a/tests/test_named_routes.py +++ b/tests/test_named_routes.py @@ -10,7 +10,6 @@ from sanic.constants import HTTP_METHODS from sanic.exceptions import URLBuildError from sanic.response import text - # ------------------------------------------------------------ # # UTF-8 # ------------------------------------------------------------ # diff --git a/tests/test_prepare.py b/tests/test_prepare.py index 79786964..5fd55410 100644 --- a/tests/test_prepare.py +++ b/tests/test_prepare.py @@ -1,6 +1,5 @@ import logging import os - from pathlib import Path from unittest.mock import Mock diff --git a/tests/test_reloader.py b/tests/test_reloader.py index e75a15b3..3e880316 100644 --- a/tests/test_reloader.py +++ b/tests/test_reloader.py @@ -1,7 +1,6 @@ import os import secrets import sys - from contextlib import suppress from subprocess import PIPE, Popen, TimeoutExpired from tempfile import TemporaryDirectory @@ -11,7 +10,6 @@ from time import sleep import pytest - # We need to interrupt the autoreloader without killing it, so that the server gets terminated # https://stefan.sofa-rockers.org/2013/08/15/handling-sub-process-hierarchies-python-linux-os-x/ diff --git a/tests/test_request.py b/tests/test_request.py index 2a527043..6f59317d 100644 --- a/tests/test_request.py +++ b/tests/test_request.py @@ -1,5 +1,4 @@ import uuid - from unittest.mock import Mock from uuid import UUID, uuid4 diff --git a/tests/test_request_data.py b/tests/test_request_data.py index 51f2b230..3e37f239 100644 --- a/tests/test_request_data.py +++ b/tests/test_request_data.py @@ -2,7 +2,6 @@ import random from sanic.response import json - try: from ujson import loads except ImportError: diff --git a/tests/test_request_stream.py b/tests/test_request_stream.py index 2d43ffc7..5d5b8226 100644 --- a/tests/test_request_stream.py +++ b/tests/test_request_stream.py @@ -8,7 +8,6 @@ from sanic.response import json, text from sanic.views import HTTPMethodView from sanic.views import stream as stream_decorator - data = "abc" * 1_000_000 diff --git a/tests/test_requests.py b/tests/test_requests.py index db8aca2e..5f4567f9 100644 --- a/tests/test_requests.py +++ b/tests/test_requests.py @@ -1,12 +1,10 @@ import base64 import logging - from json import dumps as json_dumps from json import loads as json_loads from urllib.parse import urlparse import pytest - from sanic_testing.testing import ( ASGI_BASE_URL, ASGI_PORT, diff --git a/tests/test_response.py b/tests/test_response.py index 1646cfe9..08cb899b 100644 --- a/tests/test_response.py +++ b/tests/test_response.py @@ -2,7 +2,6 @@ import asyncio import inspect import os import time - from collections import namedtuple from datetime import datetime, timedelta from email.utils import formatdate, parsedate_to_datetime @@ -14,7 +13,6 @@ from typing import Callable, List, Union from urllib.parse import unquote import pytest - from aiofiles import os as async_os from pytest import LogCaptureFixture @@ -33,7 +31,6 @@ from sanic.response import ( text, ) - JSON_DATA = {"ok": True} diff --git a/tests/test_response_json.py b/tests/test_response_json.py index a56e2fa1..69179925 100644 --- a/tests/test_response_json.py +++ b/tests/test_response_json.py @@ -1,5 +1,4 @@ import json - from functools import partial from unittest.mock import Mock @@ -10,7 +9,6 @@ from sanic.exceptions import SanicException from sanic.response import json as json_response from sanic.response.types import JSONResponse - JSON_BODY = {"ok": True} json_dumps = partial(json.dumps, separators=(",", ":")) diff --git a/tests/test_response_timeout.py b/tests/test_response_timeout.py index bd4ccc9b..84424c9d 100644 --- a/tests/test_response_timeout.py +++ b/tests/test_response_timeout.py @@ -1,6 +1,5 @@ import asyncio import logging - from time import sleep import pytest diff --git a/tests/test_routes.py b/tests/test_routes.py index 903fa55f..e1ffe3cf 100644 --- a/tests/test_routes.py +++ b/tests/test_routes.py @@ -2,7 +2,6 @@ import asyncio import re import pytest - from sanic_routing.exceptions import ( InvalidUsage, ParameterNameConflicts, diff --git a/tests/test_server_events.py b/tests/test_server_events.py index ab0475b6..e88ea018 100644 --- a/tests/test_server_events.py +++ b/tests/test_server_events.py @@ -1,16 +1,13 @@ import asyncio import signal - from contextlib import closing from socket import socket import pytest - from sanic_testing.testing import HOST, PORT from sanic.exceptions import BadRequest, SanicException - AVAILABLE_LISTENERS = [ "before_server_start", "after_server_start", diff --git a/tests/test_server_loop.py b/tests/test_server_loop.py index 30077178..2026ae0d 100644 --- a/tests/test_server_loop.py +++ b/tests/test_server_loop.py @@ -1,5 +1,4 @@ import logging - from unittest.mock import Mock, patch import pytest diff --git a/tests/test_signal_handlers.py b/tests/test_signal_handlers.py index 728c9c17..ee41248e 100644 --- a/tests/test_signal_handlers.py +++ b/tests/test_signal_handlers.py @@ -1,14 +1,12 @@ import asyncio import os import signal - from queue import Queue from types import SimpleNamespace from typing import Optional from unittest.mock import MagicMock import pytest - from sanic_testing.testing import HOST, PORT from sanic import Sanic diff --git a/tests/test_signals.py b/tests/test_signals.py index 8a564a98..3fa97923 100644 --- a/tests/test_signals.py +++ b/tests/test_signals.py @@ -1,11 +1,9 @@ import asyncio - from enum import Enum from inspect import isawaitable from itertools import count import pytest - from sanic_routing.exceptions import NotFound from sanic import Blueprint, Sanic, empty diff --git a/tests/test_static.py b/tests/test_static.py index 0fd0c97b..458feb32 100644 --- a/tests/test_static.py +++ b/tests/test_static.py @@ -1,7 +1,6 @@ import logging import os import sys - from collections import Counter from pathlib import Path from time import gmtime, strftime diff --git a/tests/test_static_directory.py b/tests/test_static_directory.py index 5aab3021..81592f45 100644 --- a/tests/test_static_directory.py +++ b/tests/test_static_directory.py @@ -1,5 +1,4 @@ import os - from pathlib import Path import pytest diff --git a/tests/test_tasks.py b/tests/test_tasks.py index 1d528319..98fb6a77 100644 --- a/tests/test_tasks.py +++ b/tests/test_tasks.py @@ -1,5 +1,4 @@ import asyncio - from asyncio.tasks import Task from unittest.mock import Mock, call @@ -9,7 +8,6 @@ from sanic.app import Sanic from sanic.application.state import ApplicationServerInfo, ServerStage from sanic.response import empty - try: from unittest.mock import AsyncMock except ImportError: diff --git a/tests/test_test_client_port.py b/tests/test_test_client_port.py index 334edde3..ceef3457 100644 --- a/tests/test_test_client_port.py +++ b/tests/test_test_client_port.py @@ -2,7 +2,6 @@ from sanic_testing.testing import PORT, SanicTestClient from sanic.response import json, text - # ------------------------------------------------------------ # # UTF-8 # ------------------------------------------------------------ # diff --git a/tests/test_timeout_logic.py b/tests/test_timeout_logic.py index 497deda9..e782ea8f 100644 --- a/tests/test_timeout_logic.py +++ b/tests/test_timeout_logic.py @@ -1,5 +1,4 @@ import asyncio - from unittest.mock import Mock import pytest diff --git a/tests/test_tls.py b/tests/test_tls.py index 6d2cb981..e8050e26 100644 --- a/tests/test_tls.py +++ b/tests/test_tls.py @@ -3,7 +3,6 @@ import os import ssl import subprocess import sys - from contextlib import contextmanager from multiprocessing import Event from pathlib import Path @@ -11,11 +10,9 @@ from unittest.mock import Mock, patch from urllib.parse import urlparse import pytest - from sanic_testing.testing import HOST, PORT, SanicTestClient import sanic.http.tls.creators - from sanic import Sanic from sanic.application.constants import Mode from sanic.compat import use_context @@ -31,7 +28,6 @@ from sanic.http.tls.creators import ( from sanic.response import text from sanic.worker.loader import CertLoader - current_dir = os.path.dirname(os.path.realpath(__file__)) localhost_dir = os.path.join(current_dir, "certs/localhost") password_dir = os.path.join(current_dir, "certs/password") diff --git a/tests/test_touchup.py b/tests/test_touchup.py index 85142685..2cd0735f 100644 --- a/tests/test_touchup.py +++ b/tests/test_touchup.py @@ -1,7 +1,6 @@ import logging import pytest - from sanic_routing.exceptions import NotFound from sanic.signals import RESERVED_NAMESPACES diff --git a/tests/test_unix_socket.py b/tests/test_unix_socket.py index bd76ca74..1dd90a52 100644 --- a/tests/test_unix_socket.py +++ b/tests/test_unix_socket.py @@ -2,14 +2,12 @@ import logging import os import sys - from asyncio import AbstractEventLoop, sleep from string import ascii_lowercase import httpcore import httpx import pytest - from pytest import LogCaptureFixture from sanic import Sanic @@ -17,7 +15,6 @@ from sanic.compat import use_context from sanic.request import Request from sanic.response import text - # import platform # import subprocess # import sys diff --git a/tests/test_url_building.py b/tests/test_url_building.py index 7f9b4eb7..4e1c6ac9 100644 --- a/tests/test_url_building.py +++ b/tests/test_url_building.py @@ -1,9 +1,7 @@ import string - from urllib.parse import parse_qsl, urlsplit import pytest - from sanic_testing.testing import HOST as test_host from sanic_testing.testing import PORT as test_port @@ -13,7 +11,6 @@ from sanic.exceptions import URLBuildError from sanic.response import text from sanic.views import HTTPMethodView - URL_FOR_ARGS1 = {"arg1": ["v1", "v2"]} URL_FOR_VALUE1 = "/myurl?arg1=v1&arg1=v2" URL_FOR_ARGS2 = {"arg1": ["v1", "v2"], "_anchor": "anchor"} diff --git a/tests/test_url_for.py b/tests/test_url_for.py index 6ec6a93f..c27ca749 100644 --- a/tests/test_url_for.py +++ b/tests/test_url_for.py @@ -1,7 +1,6 @@ import asyncio import pytest - from sanic_testing.testing import SanicTestClient from sanic.blueprints import Blueprint diff --git a/tests/test_utf8.py b/tests/test_utf8.py index a2bf893e..a025baaa 100644 --- a/tests/test_utf8.py +++ b/tests/test_utf8.py @@ -2,7 +2,6 @@ from json import dumps as json_dumps from sanic.response import text - # ------------------------------------------------------------ # # UTF-8 # ------------------------------------------------------------ # diff --git a/tests/test_vhosts.py b/tests/test_vhosts.py index c62c8b80..e1cef5a2 100644 --- a/tests/test_vhosts.py +++ b/tests/test_vhosts.py @@ -1,5 +1,4 @@ import pytest - from sanic_routing.exceptions import RouteExists from sanic import Sanic diff --git a/tests/test_websockets.py b/tests/test_websockets.py index dd8413b9..0d23d47e 100644 --- a/tests/test_websockets.py +++ b/tests/test_websockets.py @@ -1,16 +1,13 @@ import re - from asyncio import Event, Queue, TimeoutError from unittest.mock import Mock, call import pytest - from websockets.frames import CTRL_OPCODES, DATA_OPCODES, Frame from sanic.exceptions import ServerError from sanic.server.websockets.frame import WebsocketFrameAssembler - try: from unittest.mock import AsyncMock except ImportError: diff --git a/tests/test_ws_handlers.py b/tests/test_ws_handlers.py index 5205090d..81681d0f 100644 --- a/tests/test_ws_handlers.py +++ b/tests/test_ws_handlers.py @@ -1,12 +1,10 @@ from typing import Any, Callable, Coroutine import pytest - from websockets.client import WebSocketClientProtocol from sanic import Request, Sanic, Websocket - MimicClientType = Callable[ [WebSocketClientProtocol], Coroutine[None, None, Any] ] diff --git a/tests/typing/samples/app_default.py b/tests/typing/samples/app_default.py index 34524c50..aac412e6 100644 --- a/tests/typing/samples/app_default.py +++ b/tests/typing/samples/app_default.py @@ -1,5 +1,4 @@ from sanic import Sanic - app = Sanic("test") reveal_type(app) diff --git a/tests/typing/test_typing.py b/tests/typing/test_typing.py index 0a5f2f41..77e106c1 100644 --- a/tests/typing/test_typing.py +++ b/tests/typing/test_typing.py @@ -1,13 +1,11 @@ # flake8: noqa: E501 import subprocess - from pathlib import Path from typing import List, Tuple import pytest - CURRENT_DIR = Path(__file__).parent diff --git a/tests/worker/test_inspector.py b/tests/worker/test_inspector.py index b1773203..32b65785 100644 --- a/tests/worker/test_inspector.py +++ b/tests/worker/test_inspector.py @@ -8,7 +8,6 @@ from unittest.mock import Mock, patch from urllib.error import URLError import pytest - from sanic_testing import TestManager from sanic.cli.inspector_client import InspectorClient @@ -16,7 +15,6 @@ from sanic.helpers import Default from sanic.log import Colors from sanic.worker.inspector import Inspector - DATA = { "info": { "packages": ["foo"], diff --git a/tests/worker/test_loader.py b/tests/worker/test_loader.py index c70a2346..838e9cb5 100644 --- a/tests/worker/test_loader.py +++ b/tests/worker/test_loader.py @@ -1,5 +1,4 @@ import sys - from os import getcwd from pathlib import Path from types import SimpleNamespace @@ -10,7 +9,6 @@ import pytest from sanic.app import Sanic from sanic.worker.loader import AppLoader, CertLoader - STATIC = Path.cwd() / "tests" / "static" diff --git a/tests/worker/test_manager.py b/tests/worker/test_manager.py index ae5f4592..bc50ad87 100644 --- a/tests/worker/test_manager.py +++ b/tests/worker/test_manager.py @@ -9,7 +9,6 @@ from sanic.exceptions import ServerKilled from sanic.worker.constants import RestartOrder from sanic.worker.manager import WorkerManager - if not OS_IS_WINDOWS: from signal import SIGKILL else: diff --git a/tests/worker/test_multiplexer.py b/tests/worker/test_multiplexer.py index 8195b094..83571469 100644 --- a/tests/worker/test_multiplexer.py +++ b/tests/worker/test_multiplexer.py @@ -1,5 +1,4 @@ import sys - from multiprocessing import Event from os import environ, getpid from typing import Any, Dict, Type, Union diff --git a/tests/worker/test_reloader.py b/tests/worker/test_reloader.py index 6530c770..6f441b5e 100644 --- a/tests/worker/test_reloader.py +++ b/tests/worker/test_reloader.py @@ -1,7 +1,6 @@ import re import signal import threading - from asyncio import Event from logging import DEBUG from pathlib import Path diff --git a/tests/worker/test_shared_ctx.py b/tests/worker/test_shared_ctx.py index 9a41d496..9b26e9c0 100644 --- a/tests/worker/test_shared_ctx.py +++ b/tests/worker/test_shared_ctx.py @@ -7,7 +7,6 @@ # 38-> import logging - from ctypes import c_int32 from multiprocessing import Pipe, Queue, Value from os import environ diff --git a/tests/worker/test_worker_serve.py b/tests/worker/test_worker_serve.py index 54ff9d65..5cee5408 100644 --- a/tests/worker/test_worker_serve.py +++ b/tests/worker/test_worker_serve.py @@ -1,5 +1,4 @@ import logging - from os import environ from unittest.mock import Mock, patch diff --git a/tox.ini b/tox.ini index fabf3bb9..4f5a850d 100644 --- a/tox.ini +++ b/tox.ini @@ -20,9 +20,8 @@ commands = [testenv:lint] commands = - flake8 sanic - black --check --verbose sanic/ - isort --check-only sanic + ruff sanic + ruff format sanic --check slotscheck --verbose -m sanic [testenv:type-checking]