Skip to content

Commit f2b8464

Browse files
committed
make websockets compatible with python3.10
Signed-off-by: Harmouch101 <[email protected]>
1 parent 72498af commit f2b8464

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
"requests>=2.16.0,<3.0.0",
8888
# remove typing_extensions after python_requires>=3.8, see web3._utils.compat
8989
"typing-extensions>=3.7.4.1,<4;python_version<'3.8'",
90-
"websockets>=9.1,<10",
90+
"websockets>=9.1,<=10.0",
9191
],
9292
python_requires='>=3.6,<4',
9393
extras_require=extras_require,

web3/providers/websocket.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import json
33
import logging
44
import os
5+
import sys
56
from threading import (
67
Thread,
78
)
@@ -10,6 +11,7 @@
1011
)
1112
from typing import (
1213
Any,
14+
Dict,
1315
Optional,
1416
Type,
1517
Union,
@@ -40,6 +42,13 @@
4042
DEFAULT_WEBSOCKET_TIMEOUT = 10
4143

4244

45+
def _loop_if_py_lt_38(loop: asyncio.AbstractEventLoop) -> Dict[str, Any]:
46+
"""
47+
Helper for the removal of the loop argument in Python 3.10.
48+
"""
49+
return {"loop": loop} if sys.version_info[:2] < (3, 8) else {}
50+
51+
4352
def _start_event_loop(loop: asyncio.AbstractEventLoop) -> None:
4453
asyncio.set_event_loop(loop)
4554
loop.run_forever()
@@ -70,7 +79,7 @@ def __init__(
7079
async def __aenter__(self) -> WebSocketClientProtocol:
7180
if self.ws is None:
7281
self.ws = await connect(
73-
uri=self.endpoint_uri, loop=self.loop, **self.websocket_kwargs
82+
uri=self.endpoint_uri, **_loop_if_py_lt_38(self.loop), **self.websocket_kwargs
7483
)
7584
return self.ws
7685

0 commit comments

Comments
 (0)