fix: satisfy pyright for log redaction tests
lint / lint (push) Successful in 2m42s
test / unit (pull_request) Successful in 54s
test / integration (pull_request) Successful in 26s

This commit is contained in:
2026-06-25 03:07:03 +00:00
committed by didericis
parent ca1f14b855
commit f5fdc0ea72
@@ -12,6 +12,7 @@ import sys
import types import types
import unittest import unittest
from io import StringIO from io import StringIO
from typing import Any
from unittest.mock import patch from unittest.mock import patch
@@ -23,7 +24,7 @@ def _ensure_shims() -> None:
if "mitmproxy" not in sys.modules: if "mitmproxy" not in sys.modules:
_mm = types.ModuleType("mitmproxy") _mm = types.ModuleType("mitmproxy")
_mh = types.ModuleType("mitmproxy.http") _mh = types.ModuleType("mitmproxy.http")
_mm.http = _mh setattr(_mm, "http", _mh)
sys.modules["mitmproxy"] = _mm sys.modules["mitmproxy"] = _mm
sys.modules["mitmproxy.http"] = _mh sys.modules["mitmproxy.http"] = _mh
if "egress_addon_core" not in sys.modules: if "egress_addon_core" not in sys.modules:
@@ -104,14 +105,14 @@ class _Flow:
self.response = response or _Response() self.response = response or _Response()
def _log_request(addon: EgressAddon, flow: _Flow) -> dict: def _log_request(addon: EgressAddon, flow: _Flow) -> dict[str, Any]:
buf = StringIO() buf = StringIO()
with patch("sys.stderr", buf): with patch("sys.stderr", buf):
addon._log_request(flow) # type: ignore[arg-type] addon._log_request(flow) # type: ignore[arg-type]
return json.loads(buf.getvalue()) return json.loads(buf.getvalue())
def _log_response(addon: EgressAddon, flow: _Flow) -> dict: def _log_response(addon: EgressAddon, flow: _Flow) -> dict[str, Any]:
buf = StringIO() buf = StringIO()
with patch("sys.stderr", buf): with patch("sys.stderr", buf):
addon._log_response(flow) # type: ignore[arg-type] addon._log_response(flow) # type: ignore[arg-type]