Skip to content

Commit 486ad0d

Browse files
committed
typing fixes
1 parent 252f977 commit 486ad0d

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

litestar/logging/structlog.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ def should_log_as_json(self) -> bool:
108108
return True
109109

110110
def _get_structlog_config(self) -> dict[str, None]:
111-
if self._structlog_config is None:
111+
config = self._structlog_config
112+
if config is None:
112113
if (
113114
self.bypass_processors_under_capture_logs
114115
and (config_processors := structlog.get_config()["processors"])
@@ -142,7 +143,7 @@ def _get_structlog_config(self) -> dict[str, None]:
142143
# get around frozen dataclasses
143144
object.__setattr__(self, "_structlog_config", config)
144145

145-
return self._structlog_config
146+
return config
146147

147148
def get_litestar_logger(self, name: str | None = None) -> Logger:
148149
logger = structlog.wrap_logger(

litestar/middleware/logging.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424

2525
if TYPE_CHECKING:
26-
from collections.abc import Collection, Iterable
26+
from collections.abc import Iterable, Sequence
2727

2828
from litestar.connection import Request
2929
from litestar.logging import LoggingConfig
@@ -59,14 +59,14 @@ def __init__(
5959
response_headers_to_obfuscate: Iterable[str] = ("Authorization", "X-API-KEY"),
6060
request_log_message: str = "HTTP Request",
6161
response_log_message: str = "HTTP Response",
62-
request_log_fields: Collection[RequestExtractorField] = (
62+
request_log_fields: Sequence[RequestExtractorField] = (
6363
"path",
6464
"method",
6565
"content_type",
6666
"query",
6767
"path_params",
6868
),
69-
response_log_fields: Collection[ResponseExtractorField] = ("status_code",), # type: ignore[assignment] # Literal is not correctly infered here
69+
response_log_fields: Sequence[ResponseExtractorField] = ("status_code",),
7070
parse_body: bool = False,
7171
parse_query: bool = True,
7272
) -> None:

tests/unit/test_middleware/test_logging_middleware.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def test_logging_middleware_regular_logger(caplog: "LogCaptureFixture", handler:
6060
assert len(caplog.messages) == 2
6161

6262
assert caplog.messages[0] == "HTTP Request"
63-
assert caplog.records[0].litestar == {
63+
assert caplog.records[0].litestar == { # type: ignore[attr-defined]
6464
"path": "/",
6565
"method": "GET",
6666
"content_type": '["",{}]',
@@ -179,7 +179,7 @@ def test_logging_middleware_compressed_response_body(
179179
create_test_client(
180180
route_handlers=[handler],
181181
compression_config=CompressionConfig(backend="gzip", minimum_size=1),
182-
middleware=[LoggingMiddleware(include_compressed_body=include, response_log_fields=("body",))],
182+
middleware=[LoggingMiddleware(include_compressed_body=include, response_log_fields=["body",])],
183183
) as client,
184184
):
185185
# Set cookies on the client to avoid warnings about per-request cookies.
@@ -188,9 +188,9 @@ def test_logging_middleware_compressed_response_body(
188188
assert response.status_code == HTTP_200_OK
189189
assert len(caplog.messages) == 2
190190
if include:
191-
assert "body" in caplog.records[1].litestar
191+
assert "body" in caplog.records[1].litestar # type: ignore[attr-defined]
192192
else:
193-
assert "body" not in caplog.records[1].litestar
193+
assert "body" not in caplog.records[1].litestar # type: ignore[attr-defined]
194194

195195

196196
def test_logging_middleware_post_body() -> None:
@@ -260,9 +260,9 @@ def test_logging_middleware_log_fields(caplog: "LogCaptureFixture", handler: HTT
260260
assert len(caplog.messages) == 2
261261

262262
assert caplog.messages[0] == "HTTP Request"
263-
assert caplog.records[0].litestar == {"path": "/"}
263+
assert caplog.records[0].litestar == {"path": "/"} # type: ignore[attr-defined]
264264
assert caplog.messages[1] == "HTTP Response"
265-
assert caplog.records[1].litestar == {"status_code": 200}
265+
assert caplog.records[1].litestar == {"status_code": 200} # type: ignore[attr-defined]
266266

267267

268268
def test_logging_middleware_with_session_middleware(session_backend_config_memory: "ServerSideSessionConfig") -> None:

0 commit comments

Comments
 (0)