Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 2936414

Browse files
author
David Robertson
authoredSep 30, 2021
Pass str to twisted's IReactorTCP (#10895)
This follows a correction made in twisted/twisted#1664 and should fix our Twisted Trial CI job. Until that change is in a twisted release, we'll have to ignore the type of the `host` argument. I've raised #10899 to remind us to review the issue in a few months' time.
1 parent 3aefc7b commit 2936414

File tree

6 files changed

+27
-11
lines changed

6 files changed

+27
-11
lines changed
 

‎changelog.d/10895.misc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix type hints to be compatible with an upcoming change to Twisted.

‎synapse/handlers/send_email.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,13 @@ def build_sender_factory(**kwargs: Any) -> ESMTPSenderFactory:
105105
# set to enable TLS.
106106
factory = build_sender_factory(hostname=smtphost if enable_tls else None)
107107

108-
# the IReactorTCP interface claims host has to be a bytes, which seems to be wrong
109-
reactor.connectTCP(smtphost, smtpport, factory, timeout=30, bindAddress=None) # type: ignore[arg-type]
108+
reactor.connectTCP(
109+
smtphost, # type: ignore[arg-type]
110+
smtpport,
111+
factory,
112+
timeout=30,
113+
bindAddress=None,
114+
)
110115

111116
await make_deferred_yieldable(d)
112117

‎synapse/replication/tcp/handler.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ def start_replication(self, hs):
315315
hs, outbound_redis_connection
316316
)
317317
hs.get_reactor().connectTCP(
318-
hs.config.redis.redis_host.encode(),
318+
hs.config.redis.redis_host, # type: ignore[arg-type]
319319
hs.config.redis.redis_port,
320320
self._factory,
321321
)
@@ -324,7 +324,11 @@ def start_replication(self, hs):
324324
self._factory = DirectTcpReplicationClientFactory(hs, client_name, self)
325325
host = hs.config.worker.worker_replication_host
326326
port = hs.config.worker.worker_replication_port
327-
hs.get_reactor().connectTCP(host.encode(), port, self._factory)
327+
hs.get_reactor().connectTCP(
328+
host, # type: ignore[arg-type]
329+
port,
330+
self._factory,
331+
)
328332

329333
def get_streams(self) -> Dict[str, Stream]:
330334
"""Get a map from stream name to all streams."""

‎synapse/replication/tcp/redis.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,12 @@ def lazyConnection(
364364
factory.continueTrying = reconnect
365365

366366
reactor = hs.get_reactor()
367-
reactor.connectTCP(host.encode(), port, factory, timeout=30, bindAddress=None)
367+
reactor.connectTCP(
368+
host, # type: ignore[arg-type]
369+
port,
370+
factory,
371+
timeout=30,
372+
bindAddress=None,
373+
)
368374

369375
return factory.handler

‎tests/replication/_base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def setUp(self):
240240
if self.hs.config.redis.redis_enabled:
241241
# Handle attempts to connect to fake redis server.
242242
self.reactor.add_tcp_client_callback(
243-
b"localhost",
243+
"localhost",
244244
6379,
245245
self.connect_any_redis_attempts,
246246
)
@@ -424,7 +424,7 @@ def connect_any_redis_attempts(self):
424424
clients = self.reactor.tcpClients
425425
while clients:
426426
(host, port, client_factory, _timeout, _bindAddress) = clients.pop(0)
427-
self.assertEqual(host, b"localhost")
427+
self.assertEqual(host, "localhost")
428428
self.assertEqual(port, 6379)
429429

430430
client_protocol = client_factory.buildProtocol(None)

‎tests/server.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ class ThreadedMemoryReactorClock(MemoryReactorClock):
317317
def __init__(self):
318318
self.threadpool = ThreadPool(self)
319319

320-
self._tcp_callbacks = {}
320+
self._tcp_callbacks: Dict[Tuple[str, int], Callable] = {}
321321
self._udp = []
322322
self.lookups: Dict[str, str] = {}
323323
self._thread_callbacks: Deque[Callable[[], None]] = deque()
@@ -355,7 +355,7 @@ def callFromThread(self, callback, *args, **kwargs):
355355
def getThreadPool(self):
356356
return self.threadpool
357357

358-
def add_tcp_client_callback(self, host, port, callback):
358+
def add_tcp_client_callback(self, host: str, port: int, callback: Callable):
359359
"""Add a callback that will be invoked when we receive a connection
360360
attempt to the given IP/port using `connectTCP`.
361361
@@ -364,7 +364,7 @@ def add_tcp_client_callback(self, host, port, callback):
364364
"""
365365
self._tcp_callbacks[(host, port)] = callback
366366

367-
def connectTCP(self, host, port, factory, timeout=30, bindAddress=None):
367+
def connectTCP(self, host: str, port: int, factory, timeout=30, bindAddress=None):
368368
"""Fake L{IReactorTCP.connectTCP}."""
369369

370370
conn = super().connectTCP(
@@ -475,7 +475,7 @@ def runInteraction(interaction, *args, **kwargs):
475475
return server
476476

477477

478-
def get_clock():
478+
def get_clock() -> Tuple[ThreadedMemoryReactorClock, Clock]:
479479
clock = ThreadedMemoryReactorClock()
480480
hs_clock = Clock(clock)
481481
return clock, hs_clock

0 commit comments

Comments
 (0)
This repository has been archived.