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

Commit

Permalink
Fix some type hints for txredis.
Browse files Browse the repository at this point in the history
  • Loading branch information
clokep committed Feb 18, 2022
1 parent 444b040 commit 28449fd
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
9 changes: 6 additions & 3 deletions stubs/txredisapi.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ from twisted.internet import protocol
from twisted.internet.defer import Deferred

class RedisProtocol(protocol.Protocol):
def publish(self, channel: str, message: bytes): ...
def publish(self, channel: str, message: bytes) -> "Deferred[None]": ...
def ping(self) -> "Deferred[None]": ...
def set(
self,
Expand Down Expand Up @@ -52,11 +52,14 @@ def lazyConnection(
convertNumbers: bool = ...,
) -> RedisProtocol: ...

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

class RedisFactory(protocol.ReconnectingClientFactory):
continueTrying: bool
handler: RedisProtocol
handler: ConnectionHandler
pool: List[RedisProtocol]
replyTimeout: Optional[int]
def __init__(
Expand Down
4 changes: 2 additions & 2 deletions synapse/replication/tcp/external_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from synapse.util import json_decoder, json_encoder

if TYPE_CHECKING:
from txredisapi import RedisProtocol
from txredisapi import ConnectionHandler

from synapse.server import HomeServer

Expand Down Expand Up @@ -63,7 +63,7 @@ class ExternalCache:
def __init__(self, hs: "HomeServer"):
if hs.config.redis.redis_enabled:
self._redis_connection: Optional[
"RedisProtocol"
"ConnectionHandler"
] = hs.get_outbound_redis_connection()
else:
self._redis_connection = None
Expand Down
6 changes: 3 additions & 3 deletions synapse/replication/tcp/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class RedisSubscriber(txredisapi.SubscriberProtocol):

synapse_handler: "ReplicationCommandHandler"
synapse_stream_name: str
synapse_outbound_redis_connection: txredisapi.RedisProtocol
synapse_outbound_redis_connection: txredisapi.ConnectionHandler

def __init__(self, *args: Any, **kwargs: Any):
super().__init__(*args, **kwargs)
Expand Down Expand Up @@ -313,7 +313,7 @@ class RedisDirectTcpReplicationClientFactory(SynapseRedisFactory):
protocol = RedisSubscriber

def __init__(
self, hs: "HomeServer", outbound_redis_connection: txredisapi.RedisProtocol
self, hs: "HomeServer", outbound_redis_connection: txredisapi.ConnectionHandler
):

super().__init__(
Expand Down Expand Up @@ -353,7 +353,7 @@ def lazyConnection(
reconnect: bool = True,
password: Optional[str] = None,
replyTimeout: int = 30,
) -> txredisapi.RedisProtocol:
) -> txredisapi.ConnectionHandler:
"""Creates a connection to Redis that is lazily set up and reconnects if the
connections is lost.
"""
Expand Down
4 changes: 2 additions & 2 deletions synapse/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
logger = logging.getLogger(__name__)

if TYPE_CHECKING:
from txredisapi import RedisProtocol
from txredisapi import ConnectionHandler

from synapse.handlers.oidc import OidcHandler
from synapse.handlers.saml import SamlHandler
Expand Down Expand Up @@ -808,7 +808,7 @@ def get_external_cache(self) -> ExternalCache:
return ExternalCache(self)

@cache_in_self
def get_outbound_redis_connection(self) -> "RedisProtocol":
def get_outbound_redis_connection(self) -> "ConnectionHandler":
"""
The Redis connection used for replication.
Expand Down

0 comments on commit 28449fd

Please sign in to comment.