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

Commit

Permalink
Fix typing
Browse files Browse the repository at this point in the history
  • Loading branch information
erikjohnston committed Oct 1, 2020
1 parent 522a4e9 commit 6a0da53
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 16 deletions.
3 changes: 3 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,6 @@ ignore_missing_imports = True

[mypy-nacl.*]
ignore_missing_imports = True

[mypy-hiredis]
ignore_missing_imports = True
20 changes: 19 additions & 1 deletion stubs/txredisapi.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"""Contains *incomplete* type hints for txredisapi.
"""

from typing import List, Optional, Union
from typing import List, Optional, Union, Type

class RedisProtocol:
def publish(self, channel: str, message: bytes): ...
Expand All @@ -42,3 +42,21 @@ def lazyConnection(

class SubscriberFactory:
def buildProtocol(self, addr): ...

class ConnectionHandler: ...

class RedisFactory:
continueTrying: bool
handler: RedisProtocol
def __init__(
self,
uuid: str,
dbid: Optional[int],
poolsize: int,
isLazy: bool = False,
handler: Type = ConnectionHandler,
charset: str = "utf-8",
password: Optional[str] = None,
replyTimeout: Optional[int] = None,
convertNumbers: Optional[int] = True,
): ...
27 changes: 12 additions & 15 deletions synapse/replication/tcp/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import logging
from inspect import isawaitable
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Optional

import txredisapi

Expand Down Expand Up @@ -232,16 +232,16 @@ def buildProtocol(self, addr):

def lazyConnection(
reactor,
host="localhost",
port=6379,
dbid=None,
reconnect=True,
charset="utf-8",
password=None,
connectTimeout=None,
replyTimeout=None,
convertNumbers=True,
):
host: str = "localhost",
port: int = 6379,
dbid: Optional[int] = None,
reconnect: bool = True,
charset: str = "utf-8",
password: Optional[str] = None,
connectTimeout: Optional[int] = None,
replyTimeout: Optional[int] = None,
convertNumbers: bool = True,
) -> txredisapi.RedisProtocol:
"""Equivalent to `txredisapi.lazyConnection`, except allows specifying a
reactor.
"""
Expand All @@ -265,7 +265,4 @@ def lazyConnection(
for x in range(poolsize):
reactor.connectTCP(host, port, factory, connectTimeout)

if isLazy:
return factory.handler
else:
return factory.deferred
return factory.handler

0 comments on commit 6a0da53

Please sign in to comment.