From 3f740d375c1d767681e44d4a22ab89b6e0cb7ad0 Mon Sep 17 00:00:00 2001 From: dustinface <35775977+xdustinface@users.noreply.github.com> Date: Thu, 7 Jul 2022 04:02:09 +0200 Subject: [PATCH] plot_sync: Fix type hints in `Receiver._process` (#11890) * plot_sync: Fix type hints in `Receiver._process` * Move `PlotSyncMessage` and `T_PlotSyncMessage` into `plot_sync.util` --- chia/plot_sync/receiver.py | 5 ++--- chia/plot_sync/util.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/chia/plot_sync/receiver.py b/chia/plot_sync/receiver.py index a5827cb0cec4..f36a42a86820 100644 --- a/chia/plot_sync/receiver.py +++ b/chia/plot_sync/receiver.py @@ -14,7 +14,7 @@ from chia.plot_sync.exceptions import ( PlotSyncException, SyncIdsMatchError, ) -from chia.plot_sync.util import ErrorCodes, State +from chia.plot_sync.util import ErrorCodes, State, T_PlotSyncMessage from chia.protocols.harvester_protocol import ( Plot, PlotSyncDone, @@ -29,7 +29,6 @@ from chia.server.ws_connection import ProtocolMessageTypes, WSChiaConnection, ma from chia.types.blockchain_format.sized_bytes import bytes32 from chia.util.ints import int16, uint32, uint64 from chia.util.misc import get_list_or_len -from chia.util.streamable import _T_Streamable log = logging.getLogger(__name__) @@ -140,7 +139,7 @@ class Receiver: return self._total_plot_size async def _process( - self, method: Callable[[_T_Streamable], Any], message_type: ProtocolMessageTypes, message: Any + self, method: Callable[[T_PlotSyncMessage], Any], message_type: ProtocolMessageTypes, message: T_PlotSyncMessage ) -> None: log.debug( f"_process: node_id {self.connection().peer_node_id}, message_type: {message_type}, message: {message}" diff --git a/chia/plot_sync/util.py b/chia/plot_sync/util.py index 5776631a73d8..ad21dbd56b6b 100644 --- a/chia/plot_sync/util.py +++ b/chia/plot_sync/util.py @@ -1,4 +1,9 @@ from enum import IntEnum +from typing import TypeVar + +from typing_extensions import Protocol + +from chia.protocols.harvester_protocol import PlotSyncIdentifier class Constants: @@ -25,3 +30,12 @@ class ErrorCodes(IntEnum): plot_already_available = 5 plot_not_available = 6 sync_ids_match = 7 + + +class PlotSyncMessage(Protocol): + @property + def identifier(self) -> PlotSyncIdentifier: + pass + + +T_PlotSyncMessage = TypeVar("T_PlotSyncMessage", bound=PlotSyncMessage)