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`
This commit is contained in:
dustinface 2022-07-07 04:02:09 +02:00 committed by GitHub
parent f0c5a16c30
commit 3f740d375c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 3 deletions

View File

@ -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}"

View File

@ -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)