From 6f9ed30d23278ae9bf70d2be355d2c58b4603e82 Mon Sep 17 00:00:00 2001 From: Benoit Chesneau Date: Sun, 3 May 2026 18:23:45 +0200 Subject: [PATCH] lint: use dict literal and hoist mock import --- gunicorn/asgi/protocol.py | 20 ++++++++++---------- tests/test_http.py | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/gunicorn/asgi/protocol.py b/gunicorn/asgi/protocol.py index 5c66ece8..85b6ae39 100644 --- a/gunicorn/asgi/protocol.py +++ b/gunicorn/asgi/protocol.py @@ -488,16 +488,16 @@ class ASGIProtocol(asyncio.Protocol): # Create parser with callbacks and limit parameters (both parsers support them). # Only the Python parser implements PROXY protocol framing; pass the option there. - parser_kwargs = dict( - on_headers_complete=self._on_headers_complete, - on_body=self._on_body, - on_message_complete=self._on_message_complete, - limit_request_line=limit_request_line, - limit_request_fields=self.cfg.limit_request_fields, - limit_request_field_size=self.cfg.limit_request_field_size, - permit_unconventional_http_method=self.cfg.permit_unconventional_http_method, - permit_unconventional_http_version=self.cfg.permit_unconventional_http_version, - ) + parser_kwargs = { + 'on_headers_complete': self._on_headers_complete, + 'on_body': self._on_body, + 'on_message_complete': self._on_message_complete, + 'limit_request_line': limit_request_line, + 'limit_request_fields': self.cfg.limit_request_fields, + 'limit_request_field_size': self.cfg.limit_request_field_size, + 'permit_unconventional_http_method': self.cfg.permit_unconventional_http_method, + 'permit_unconventional_http_version': self.cfg.permit_unconventional_http_version, + } if parser_class is PythonProtocol: parser_kwargs['proxy_protocol'] = getattr(self.cfg, 'proxy_protocol', 'off') self._callback_parser = parser_class(**parser_kwargs) diff --git a/tests/test_http.py b/tests/test_http.py index 0531916d..1b3dc176 100644 --- a/tests/test_http.py +++ b/tests/test_http.py @@ -297,13 +297,13 @@ def test_finish_body_returns_false_on_expired_deadline(): b"\r\n" b"only-partial" ) + import time as _time + parser = _build_request_parser(payload) # Force an already-elapsed deadline; the drain must abandon immediately. - import time as _time expired = _time.monotonic() - 1.0 # IterUnreader has no socket; deadline path is exercised only when sock # is present. Stub a sock with gettimeout/settimeout to drive the branch. - from unittest import mock sock = mock.Mock() sock.gettimeout.return_value = None parser.unreader.sock = sock