Fix incorrect type hints for txredis. (#12042)

Some properties were marked as RedisProtocol instead of ConnectionHandler,
which wraps RedisProtocol instance(s).
pull/12181/head
Patrick Cloke 2022-03-08 07:26:05 -05:00 committed by GitHub
parent 26211fec24
commit d8bab6793c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 14 additions and 10 deletions

1
changelog.d/12042.misc Normal file
View File

@ -0,0 +1 @@
Correct type hints for txredis.

View File

@ -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,
@ -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__(

View File

@ -21,7 +21,7 @@ from synapse.logging.context import make_deferred_yieldable
from synapse.util import json_decoder, json_encoder
if TYPE_CHECKING:
from txredisapi import RedisProtocol
from txredisapi import ConnectionHandler
from synapse.server import HomeServer
@ -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

View File

@ -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)
@ -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__(
@ -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.
"""

View File

@ -145,7 +145,7 @@ from synapse.util.stringutils import random_string
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
@ -807,7 +807,7 @@ class HomeServer(metaclass=abc.ABCMeta):
return AccountHandler(self)
@cache_in_self
def get_outbound_redis_connection(self) -> "RedisProtocol":
def get_outbound_redis_connection(self) -> "ConnectionHandler":
"""
The Redis connection used for replication.