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

Pass str to twisted's IReactorTCP #10895

Merged
merged 6 commits into from
Sep 30, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/10895.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix type hints to be compatible with an upcoming change to Twisted.
9 changes: 7 additions & 2 deletions synapse/handlers/send_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,13 @@ def build_sender_factory(**kwargs: Any) -> ESMTPSenderFactory:
# set to enable TLS.
factory = build_sender_factory(hostname=smtphost if enable_tls else None)

# the IReactorTCP interface claims host has to be a bytes, which seems to be wrong
reactor.connectTCP(smtphost, smtpport, factory, timeout=30, bindAddress=None) # type: ignore[arg-type]
reactor.connectTCP(
smtphost, # type: ignore[arg-type]
smtpport,
factory,
timeout=30,
bindAddress=None,
)

await make_deferred_yieldable(d)

Expand Down
8 changes: 6 additions & 2 deletions synapse/replication/tcp/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def start_replication(self, hs):
hs, outbound_redis_connection
)
hs.get_reactor().connectTCP(
hs.config.redis.redis_host.encode(),
hs.config.redis.redis_host, # type: ignore[arg-type]
hs.config.redis.redis_port,
self._factory,
)
Expand All @@ -324,7 +324,11 @@ def start_replication(self, hs):
self._factory = DirectTcpReplicationClientFactory(hs, client_name, self)
host = hs.config.worker_replication_host
port = hs.config.worker_replication_port
hs.get_reactor().connectTCP(host.encode(), port, self._factory)
hs.get_reactor().connectTCP(
host, # type: ignore[arg-type]
port,
self._factory,
)

def get_streams(self) -> Dict[str, Stream]:
"""Get a map from stream name to all streams."""
Expand Down
8 changes: 7 additions & 1 deletion synapse/replication/tcp/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,12 @@ def lazyConnection(
factory.continueTrying = reconnect

reactor = hs.get_reactor()
reactor.connectTCP(host.encode(), port, factory, timeout=30, bindAddress=None)
reactor.connectTCP(
host, # type: ignore[arg-type]
port,
factory,
timeout=30,
bindAddress=None,
)

return factory.handler
2 changes: 1 addition & 1 deletion tests/replication/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ def connect_any_redis_attempts(self):
clients = self.reactor.tcpClients
while clients:
(host, port, client_factory, _timeout, _bindAddress) = clients.pop(0)
self.assertEqual(host, b"localhost")
self.assertEqual(host, "localhost")
self.assertEqual(port, 6379)

client_protocol = client_factory.buildProtocol(None)
Expand Down