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

Commit 28449fd

Browse files
committed
Fix some type hints for txredis.
1 parent 444b040 commit 28449fd

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

stubs/txredisapi.pyi

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ from twisted.internet import protocol
2020
from twisted.internet.defer import Deferred
2121

2222
class RedisProtocol(protocol.Protocol):
23-
def publish(self, channel: str, message: bytes): ...
23+
def publish(self, channel: str, message: bytes) -> "Deferred[None]": ...
2424
def ping(self) -> "Deferred[None]": ...
2525
def set(
2626
self,
@@ -52,11 +52,14 @@ def lazyConnection(
5252
convertNumbers: bool = ...,
5353
) -> RedisProtocol: ...
5454

55-
class ConnectionHandler: ...
55+
# ConnectionHandler doesn't actually inherit from RedisProtocol, but it proxies
56+
# most methods to it via ConnectionHandler.__getattr__.
57+
class ConnectionHandler(RedisProtocol):
58+
def disconnect(self) -> "Deferred[None]": ...
5659

5760
class RedisFactory(protocol.ReconnectingClientFactory):
5861
continueTrying: bool
59-
handler: RedisProtocol
62+
handler: ConnectionHandler
6063
pool: List[RedisProtocol]
6164
replyTimeout: Optional[int]
6265
def __init__(

synapse/replication/tcp/external_cache.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from synapse.util import json_decoder, json_encoder
2222

2323
if TYPE_CHECKING:
24-
from txredisapi import RedisProtocol
24+
from txredisapi import ConnectionHandler
2525

2626
from synapse.server import HomeServer
2727

@@ -63,7 +63,7 @@ class ExternalCache:
6363
def __init__(self, hs: "HomeServer"):
6464
if hs.config.redis.redis_enabled:
6565
self._redis_connection: Optional[
66-
"RedisProtocol"
66+
"ConnectionHandler"
6767
] = hs.get_outbound_redis_connection()
6868
else:
6969
self._redis_connection = None

synapse/replication/tcp/redis.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class RedisSubscriber(txredisapi.SubscriberProtocol):
9393

9494
synapse_handler: "ReplicationCommandHandler"
9595
synapse_stream_name: str
96-
synapse_outbound_redis_connection: txredisapi.RedisProtocol
96+
synapse_outbound_redis_connection: txredisapi.ConnectionHandler
9797

9898
def __init__(self, *args: Any, **kwargs: Any):
9999
super().__init__(*args, **kwargs)
@@ -313,7 +313,7 @@ class RedisDirectTcpReplicationClientFactory(SynapseRedisFactory):
313313
protocol = RedisSubscriber
314314

315315
def __init__(
316-
self, hs: "HomeServer", outbound_redis_connection: txredisapi.RedisProtocol
316+
self, hs: "HomeServer", outbound_redis_connection: txredisapi.ConnectionHandler
317317
):
318318

319319
super().__init__(
@@ -353,7 +353,7 @@ def lazyConnection(
353353
reconnect: bool = True,
354354
password: Optional[str] = None,
355355
replyTimeout: int = 30,
356-
) -> txredisapi.RedisProtocol:
356+
) -> txredisapi.ConnectionHandler:
357357
"""Creates a connection to Redis that is lazily set up and reconnects if the
358358
connections is lost.
359359
"""

synapse/server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@
144144
logger = logging.getLogger(__name__)
145145

146146
if TYPE_CHECKING:
147-
from txredisapi import RedisProtocol
147+
from txredisapi import ConnectionHandler
148148

149149
from synapse.handlers.oidc import OidcHandler
150150
from synapse.handlers.saml import SamlHandler
@@ -808,7 +808,7 @@ def get_external_cache(self) -> ExternalCache:
808808
return ExternalCache(self)
809809

810810
@cache_in_self
811-
def get_outbound_redis_connection(self) -> "RedisProtocol":
811+
def get_outbound_redis_connection(self) -> "ConnectionHandler":
812812
"""
813813
The Redis connection used for replication.
814814

0 commit comments

Comments
 (0)