Skip to content
This repository was archived by the owner on Jul 1, 2021. It is now read-only.

Commit fba0ffb

Browse files
veoxcburgdorf
authored andcommitted
ethstats_client: typing fixes (for linting).
websockets.client.WebSocketClientProtocol.recv() can return either `str` or `bytes`, depending on: https://websockets.readthedocs.io/en/stable/api.html#websockets.protocol.WebSocketCommonProtocol.recv To quote: > Return a str for a text frame and bytes for a binary frame. For now, ignore the issue.
1 parent 2fed529 commit fba0ffb

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

trinity/components/builtin/ethstats/ethstats_client.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import asyncio
22
import datetime
33
import json
4-
import typing
4+
5+
from typing import (
6+
Any,
7+
Dict,
8+
NamedTuple,
9+
)
510

611
import websockets
712

@@ -19,10 +24,10 @@ def timestamp_ms() -> int:
1924
return round(datetime.datetime.utcnow().timestamp() * 1000)
2025

2126

22-
EthstatsData = typing.Dict[str, typing.Any]
27+
EthstatsData = Dict[str, Any]
2328

2429

25-
class EthstatsMessage(typing.NamedTuple):
30+
class EthstatsMessage(NamedTuple):
2631
command: str
2732
data: EthstatsData
2833

@@ -56,12 +61,12 @@ async def _run(self) -> None:
5661
async def recv_handler(self) -> None:
5762
while self.is_operational:
5863
try:
59-
json_string: str = await self.websocket.recv()
64+
json_string = await self.websocket.recv()
6065
except websockets.ConnectionClosed as e:
6166
self.logger.debug2("Connection closed: %s", e)
6267
await self.cancel()
6368
try:
64-
message: EthstatsMessage = self.deserialize_message(json_string)
69+
message: EthstatsMessage = self.deserialize_message(str(json_string))
6570
except EthstatsException as e:
6671
self.logger.warning('Cannot parse message from server: %s' % e)
6772
return

0 commit comments

Comments
 (0)