From df5d7ad6d2c3cd0f5424a9504cd9c50fd56f65a4 Mon Sep 17 00:00:00 2001 From: Benoit Chesneau Date: Tue, 27 Jan 2026 10:03:54 +0100 Subject: [PATCH] fix: resolve ruff lint warnings in HTTP/2 code - Remove unused imports in test files - Rename loop variable to avoid shadowing sock import - Remove unused ssock variable in conftest --- gunicorn/workers/gthread.py | 8 ++++---- tests/docker/http2/conftest.py | 4 +--- tests/test_http2_alpn.py | 1 - tests/test_http2_async_connection.py | 2 +- tests/test_http2_connection.py | 2 +- tests/test_http2_request.py | 1 - tests/test_http2_stream.py | 1 - 7 files changed, 7 insertions(+), 12 deletions(-) diff --git a/gunicorn/workers/gthread.py b/gunicorn/workers/gthread.py index 0e3f5e2d..20e3d60c 100644 --- a/gunicorn/workers/gthread.py +++ b/gunicorn/workers/gthread.py @@ -216,12 +216,12 @@ class ThreadWorker(base.Worker): if enabled == self._accepting: return - for sock in self.sockets: + for listener in self.sockets: if enabled: - sock.setblocking(False) - self.poller.register(sock, selectors.EVENT_READ, self.accept) + listener.setblocking(False) + self.poller.register(listener, selectors.EVENT_READ, self.accept) else: - self.poller.unregister(sock) + self.poller.unregister(listener) self._accepting = enabled diff --git a/tests/docker/http2/conftest.py b/tests/docker/http2/conftest.py index d01ad992..b9cdc180 100644 --- a/tests/docker/http2/conftest.py +++ b/tests/docker/http2/conftest.py @@ -1,7 +1,5 @@ """Pytest fixtures for HTTP/2 Docker integration tests.""" -import os -import shutil import subprocess import time from pathlib import Path @@ -62,7 +60,7 @@ def wait_for_service(url: str, timeout: int = 60) -> bool: ctx.verify_mode = ssl.CERT_NONE with socket.create_connection((host, port), timeout=5) as sock: - with ctx.wrap_socket(sock, server_hostname=host) as ssock: + with ctx.wrap_socket(sock, server_hostname=host): return True except (socket.error, ssl.SSLError, OSError): time.sleep(1) diff --git a/tests/test_http2_alpn.py b/tests/test_http2_alpn.py index 4e52d349..39c91648 100644 --- a/tests/test_http2_alpn.py +++ b/tests/test_http2_alpn.py @@ -10,7 +10,6 @@ import pytest from unittest import mock from gunicorn import sock -from gunicorn.config import Config def create_mock_ssl_socket(alpn_protocol=None): diff --git a/tests/test_http2_async_connection.py b/tests/test_http2_async_connection.py index 606261f5..1160b0d6 100644 --- a/tests/test_http2_async_connection.py +++ b/tests/test_http2_async_connection.py @@ -20,7 +20,7 @@ except ImportError: H2_AVAILABLE = False from gunicorn.http2.errors import ( - HTTP2Error, HTTP2ProtocolError, HTTP2ConnectionError + HTTP2Error, HTTP2ConnectionError ) diff --git a/tests/test_http2_connection.py b/tests/test_http2_connection.py index 4acd0dd2..da528677 100644 --- a/tests/test_http2_connection.py +++ b/tests/test_http2_connection.py @@ -20,7 +20,7 @@ except ImportError: H2_AVAILABLE = False from gunicorn.http2.errors import ( - HTTP2Error, HTTP2ProtocolError, HTTP2ConnectionError, HTTP2NotAvailable + HTTP2Error, HTTP2ConnectionError ) diff --git a/tests/test_http2_request.py b/tests/test_http2_request.py index cf21b15c..2b6c0027 100644 --- a/tests/test_http2_request.py +++ b/tests/test_http2_request.py @@ -6,7 +6,6 @@ """Tests for HTTP/2 request and body classes.""" import pytest -from unittest import mock from gunicorn.http2.request import HTTP2Request, HTTP2Body from gunicorn.http2.stream import HTTP2Stream diff --git a/tests/test_http2_stream.py b/tests/test_http2_stream.py index bff66d0a..35f5a9b5 100644 --- a/tests/test_http2_stream.py +++ b/tests/test_http2_stream.py @@ -6,7 +6,6 @@ """Tests for HTTP/2 stream state management.""" import pytest -from unittest import mock from gunicorn.http2.stream import HTTP2Stream, StreamState from gunicorn.http2.errors import HTTP2StreamError