From e1f6e2c8127cd16edc579de30e3a55d9a728f7bc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 2 Nov 2024 11:37:18 +0000 Subject: [PATCH] Bump the mypy group with 2 updates (#7291) --- updated-dependencies: - dependency-name: mypy dependency-type: direct:production dependency-group: mypy - dependency-name: types-requests dependency-type: direct:production dependency-group: mypy ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- mitmproxy/coretypes/serializable.py | 15 +++++++-------- mitmproxy/platform/windows.py | 9 +++++---- mitmproxy/proxy/layers/quic/_raw_layers.py | 5 ++++- pyproject.toml | 4 ++-- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/mitmproxy/coretypes/serializable.py b/mitmproxy/coretypes/serializable.py index ca1c31fa0..e771f611e 100644 --- a/mitmproxy/coretypes/serializable.py +++ b/mitmproxy/coretypes/serializable.py @@ -79,7 +79,7 @@ class SerializableDataclass(Serializable): return tuple(fields) def get_state(self) -> State: - state = {} + state: dict[str, State] = {} for field in self.__fields(): val = getattr(self, field.name) state[field.name] = _to_state(val, field.type, field.name) @@ -105,7 +105,7 @@ class SerializableDataclass(Serializable): continue except dataclasses.FrozenInstanceError: pass - val = _to_val(f_state, field.type, field.name) + val: typing.Any = _to_val(f_state, field.type, field.name) try: setattr(self, field.name, val) except dataclasses.FrozenInstanceError: @@ -118,10 +118,9 @@ class SerializableDataclass(Serializable): ) -V = TypeVar("V") - - -def _process(attr_val: typing.Any, attr_type: type[V], attr_name: str, make: bool) -> V: +def _process( + attr_val: typing.Any, attr_type: typing.Any, attr_name: str, make: bool +) -> typing.Any: origin = typing.get_origin(attr_type) if origin is typing.Literal: if attr_val not in typing.get_args(attr_type): @@ -190,11 +189,11 @@ def _process(attr_val: typing.Any, attr_type: type[V], attr_name: str, make: boo raise TypeError(f"Unexpected type for {attr_name}: {attr_type!r}") -def _to_val(state: typing.Any, attr_type: type[U], attr_name: str) -> U: +def _to_val(state: typing.Any, attr_type: typing.Any, attr_name: str) -> typing.Any: """Create an object based on the state given in val.""" return _process(state, attr_type, attr_name, True) -def _to_state(value: typing.Any, attr_type: type[U], attr_name: str) -> U: +def _to_state(value: typing.Any, attr_type: typing.Any, attr_name: str) -> typing.Any: """Get the state of the object given as val.""" return _process(value, attr_type, attr_name, False) diff --git a/mitmproxy/platform/windows.py b/mitmproxy/platform/windows.py index a42f649e1..2f34a29cd 100644 --- a/mitmproxy/platform/windows.py +++ b/mitmproxy/platform/windows.py @@ -12,10 +12,10 @@ import socketserver import threading import time from collections.abc import Callable +from io import BufferedIOBase from typing import Any from typing import cast from typing import ClassVar -from typing import IO import pydivert.consts @@ -33,14 +33,14 @@ logger = logging.getLogger(__name__) # Resolver -def read(rfile: IO[bytes]) -> Any: +def read(rfile: BufferedIOBase) -> Any: x = rfile.readline().strip() if not x: return None return json.loads(x) -def write(data, wfile: IO[bytes]) -> None: +def write(data, wfile: BufferedIOBase) -> None: wfile.write(json.dumps(data).encode() + b"\n") wfile.flush() @@ -465,7 +465,8 @@ class TransparentProxy: # TODO: Make sure that server can be killed cleanly. That's a bit difficult as we don't have access to # controller.should_exit when this is called. logger.warning( - "Transparent mode on Windows is unsupported and flaky. Consider using local redirect mode or WireGuard mode instead." + "Transparent mode on Windows is unsupported, flaky, and deprecated. " + "Consider using local redirect mode or WireGuard mode instead." ) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server_unavailable = s.connect_ex((REDIRECT_API_HOST, REDIRECT_API_PORT)) diff --git a/mitmproxy/proxy/layers/quic/_raw_layers.py b/mitmproxy/proxy/layers/quic/_raw_layers.py index 18d1a367a..81f34e7f8 100644 --- a/mitmproxy/proxy/layers/quic/_raw_layers.py +++ b/mitmproxy/proxy/layers/quic/_raw_layers.py @@ -20,6 +20,7 @@ from ._events import QuicStreamDataReceived from ._events import QuicStreamEvent from ._events import QuicStreamReset from mitmproxy import connection +from mitmproxy.connection import Connection from mitmproxy.proxy import commands from mitmproxy.proxy import context from mitmproxy.proxy import events @@ -259,7 +260,9 @@ class RawQuicLayer(layer.Layer): yield from self.event_to_child(stream_layer, events.Start()) # forward data and close events - conn = stream_layer.client if from_client else stream_layer.server + conn: Connection = ( + stream_layer.client if from_client else stream_layer.server + ) if isinstance(event, QuicStreamDataReceived): if event.data: yield from self.event_to_child( diff --git a/pyproject.toml b/pyproject.toml index e34265b08..dc72d3167 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -77,12 +77,12 @@ dev = [ "tox>=4.15.1,<=4.23.2", "wheel>=0.36.2,<=0.44.0", "build>=0.10.0,<=1.2.2.post1", - "mypy>=1.10.1,<=1.11.2", + "mypy>=1.10.1,<=1.13.0", "ruff>=0.5.0,<=0.7.2", "types-certifi>=2021.10.8.3,<=2021.10.8.3", "types-Flask>=1.1.6,<=1.1.6", "types-Werkzeug>=1.0.9,<=1.0.9", - "types-requests>=2.32.0.20240622,<=2.32.0.20240914", + "types-requests>=2.32.0.20240622,<=2.32.0.20241016", "types-cryptography>=3.3.23.2,<=3.3.23.2", "types-pyOpenSSL>=23.3.0.0,<=24.1.0.20240722", ]