typing: Convert function type annotations to Python 3 style.
Generated by com2ann (slightly patched to avoid also converting assignment type annotations, which require Python 3.6), followed by some manual whitespace adjustment, and two fixes for use-before-define issues: - def set_zulip_client(self, zulipToJabberClient: ZulipToJabberBot) -> None: + def set_zulip_client(self, zulipToJabberClient: 'ZulipToJabberBot') -> None: -def init_from_options(options: Any, client: Optional[str] = None) -> Client: +def init_from_options(options: Any, client: Optional[str] = None) -> 'Client': Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
parent
7c5f73dce9
commit
5428c5f296
42 changed files with 311 additions and 577 deletions
|
@ -82,8 +82,7 @@ else:
|
|||
("tabbott-nagios-test", "a"),
|
||||
]
|
||||
|
||||
def print_status_and_exit(status):
|
||||
# type: (int) -> None
|
||||
def print_status_and_exit(status: int) -> None:
|
||||
|
||||
# The output of this script is used by Nagios. Various outputs,
|
||||
# e.g. true success and punting due to a SERVNAK, result in a
|
||||
|
@ -92,8 +91,7 @@ def print_status_and_exit(status):
|
|||
print(status)
|
||||
sys.exit(status)
|
||||
|
||||
def send_zulip(message):
|
||||
# type: (Dict[str, str]) -> None
|
||||
def send_zulip(message: Dict[str, str]) -> None:
|
||||
result = zulip_client.send_message(message)
|
||||
if result["result"] != "success":
|
||||
logger.error("Error sending zulip, args were:")
|
||||
|
@ -102,8 +100,7 @@ def send_zulip(message):
|
|||
print_status_and_exit(1)
|
||||
|
||||
# Returns True if and only if we "Detected server failure" sending the zephyr.
|
||||
def send_zephyr(zwrite_args, content):
|
||||
# type: (List[str], str) -> bool
|
||||
def send_zephyr(zwrite_args: List[str], content: str) -> bool:
|
||||
p = subprocess.Popen(zwrite_args, stdin=subprocess.PIPE,
|
||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
stdout, stderr = p.communicate(input=content.encode("utf-8"))
|
||||
|
@ -167,16 +164,14 @@ if not actually_subscribed:
|
|||
# Prepare keys
|
||||
zhkeys = {} # type: Dict[str, Tuple[str, str]]
|
||||
hzkeys = {} # type: Dict[str, Tuple[str, str]]
|
||||
def gen_key(key_dict):
|
||||
# type: (Dict[str, Any]) -> str
|
||||
def gen_key(key_dict: Dict[str, Any]) -> str:
|
||||
bits = str(random.getrandbits(32))
|
||||
while bits in key_dict:
|
||||
# Avoid the unlikely event that we get the same bits twice
|
||||
bits = str(random.getrandbits(32))
|
||||
return bits
|
||||
|
||||
def gen_keys(key_dict):
|
||||
# type: (Dict[str, Tuple[str, str]]) -> None
|
||||
def gen_keys(key_dict: Dict[str, Tuple[str, str]]) -> None:
|
||||
for (stream, test) in test_streams:
|
||||
key_dict[gen_key(key_dict)] = (stream, test)
|
||||
|
||||
|
@ -188,8 +183,7 @@ notices = []
|
|||
# We check for new zephyrs multiple times, to avoid filling the zephyr
|
||||
# receive queue with 30+ messages, which might result in messages
|
||||
# being dropped.
|
||||
def receive_zephyrs():
|
||||
# type: () -> None
|
||||
def receive_zephyrs() -> None:
|
||||
while True:
|
||||
try:
|
||||
notice = zephyr.receive(block=False)
|
||||
|
@ -271,8 +265,7 @@ receive_zephyrs()
|
|||
logger.info("Finished receiving Zephyr messages!")
|
||||
|
||||
all_keys = set(list(zhkeys.keys()) + list(hzkeys.keys()))
|
||||
def process_keys(content_list):
|
||||
# type: (List[str]) -> Tuple[Dict[str, int], Set[str], Set[str], bool, bool]
|
||||
def process_keys(content_list: List[str]) -> Tuple[Dict[str, int], Set[str], Set[str], bool, bool]:
|
||||
|
||||
# Start by filtering out any keys that might have come from
|
||||
# concurrent check-mirroring processes
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue