python: 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 six fixes for runtime issues:

-    def __init__(self, token: Token, parent: Optional[Node]) -> None:
+    def __init__(self, token: Token, parent: "Optional[Node]") -> None:

-def main(options: argparse.Namespace) -> NoReturn:
+def main(options: argparse.Namespace) -> "NoReturn":

-def fetch_request(url: str, callback: Any, **kwargs: Any) -> Generator[Callable[..., Any], Any, None]:
+def fetch_request(url: str, callback: Any, **kwargs: Any) -> "Generator[Callable[..., Any], Any, None]":

-def assert_server_running(server: subprocess.Popen[bytes], log_file: Optional[str]) -> None:
+def assert_server_running(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> None:

-def server_is_up(server: subprocess.Popen[bytes], log_file: Optional[str]) -> bool:
+def server_is_up(server: "subprocess.Popen[bytes]", log_file: Optional[str]) -> bool:

-    method_kwarg_pairs: List[FuncKwargPair],
+    method_kwarg_pairs: "List[FuncKwargPair]",

Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
This commit is contained in:
Anders Kaseorg
2020-04-18 18:48:37 -07:00
committed by Tim Abbott
parent 43ac901ad9
commit 5901e7ba7e
68 changed files with 389 additions and 691 deletions

View File

@@ -85,8 +85,7 @@ states = {
"UNKNOWN": 3
}
def report(state, timestamp=None, msg=None):
# type: (str, Any, Optional[str]) -> None
def report(state: str, timestamp: Any = None, msg: Optional[str] = None) -> None:
now = int(time.time())
if msg is None:
msg = "send time was %s" % (timestamp,)
@@ -97,14 +96,12 @@ def report(state, timestamp=None, msg=None):
print("%s: %s" % (state, msg))
exit(states[state])
def send_zulip(sender, message):
# type: (zulip.Client, Dict[str, Any]) -> None
def send_zulip(sender: zulip.Client, message: Dict[str, Any]) -> None:
result = sender.send_message(message)
if result["result"] != "success" and options.nagios:
report("CRITICAL", msg="Error sending Zulip, args were: %s, %s" % (message, result))
def get_zulips():
# type: () -> List[Dict[str, Any]]
def get_zulips() -> List[Dict[str, Any]]:
global queue_id, last_event_id
res = zulip_recipient.get_events(queue_id=queue_id, last_event_id=last_event_id)
if 'error' in res.get('result', {}):

View File

@@ -20,13 +20,11 @@ states = {
"UNKNOWN": 3
}
def report(state, msg):
# type: (str, str) -> NoReturn
def report(state: str, msg: str) -> NoReturn:
print("%s: %s" % (state, msg))
exit(states[state])
def get_loc_over_ssh(host, func):
# type: (str, str) -> str
def get_loc_over_ssh(host: str, func: str) -> str:
try:
return subprocess.check_output(['ssh', host,
'psql -v ON_ERROR_STOP=1 zulip -t -c "SELECT %s()"' % (func,)],
@@ -35,8 +33,7 @@ def get_loc_over_ssh(host, func):
except subprocess.CalledProcessError as e:
report('CRITICAL', 'ssh failed: %s: %s' % (str(e), e.output))
def loc_to_abs_offset(loc_str):
# type: (str) -> int
def loc_to_abs_offset(loc_str: str) -> int:
m = re.match(r'^\s*([0-9a-fA-F]+)/([0-9a-fA-F]+)\s*$', loc_str)
if not m:
raise ValueError("Unknown xlog location format: " + loc_str)

View File

@@ -21,8 +21,7 @@ states = {
"UNKNOWN": 3
}
def report(state, num):
# type: (str, str) -> None
def report(state: str, num: str) -> None:
print("%s: %s rows in fts_update_log table" % (state, num))
exit(states[state])

View File

@@ -13,8 +13,7 @@ states = {
"UNKNOWN": 3
}
def report(state, msg):
# type: (str, str) -> None
def report(state: str, msg: str) -> None:
print("%s: %s" % (state, msg))
exit(states[state])

View File

@@ -16,8 +16,7 @@ logging.Formatter.converter = time.gmtime
logging.basicConfig(format="%(asctime)s %(levelname)s: %(message)s")
logger = logging.getLogger(__name__)
def run(args, dry_run=False):
# type: (List[str], bool) -> str
def run(args: List[str], dry_run: bool = False) -> str:
if dry_run:
print("Would have run: " + " ".join(map(shlex.quote, args)))
return ""

View File

@@ -33,8 +33,7 @@ import os
BATCH_SIZE = 1000
def update_fts_columns(cursor):
# type: (psycopg2.extensions.cursor) -> int
def update_fts_columns(cursor: psycopg2.extensions.cursor) -> int:
cursor.execute("SELECT id, message_id FROM fts_update_log LIMIT %s;" % (
BATCH_SIZE,))
ids = []
@@ -52,8 +51,7 @@ def update_fts_columns(cursor):
cursor.execute("DELETE FROM fts_update_log WHERE id = ANY(%s)", (ids,))
return len(ids)
def am_master(cursor):
# type: (psycopg2.extensions.cursor) -> bool
def am_master(cursor: psycopg2.extensions.cursor) -> bool:
cursor.execute("SELECT pg_is_in_recovery()")
return not cursor.fetchall()[0][0]

View File

@@ -21,8 +21,7 @@ states = {
"UNKNOWN": 3
} # type: Dict[str, int]
def report(state, output):
# type: (str, str) -> None
def report(state: str, output: str) -> None:
print("%s\n%s" % (state, output))
exit(states[state])

View File

@@ -35,8 +35,7 @@ states = {
"UNKNOWN": 3
} # type: Dict[str, int]
def report(state, short_msg, too_old=None):
# type: (str, str, Optional[Set[Any]]) -> None
def report(state: str, short_msg: str, too_old: Optional[Set[Any]] = None) -> None:
too_old_data = ""
if too_old:
too_old_data = "\nLast call to get_message for recently out of date mirrors:\n" + "\n".join(

View File

@@ -22,8 +22,7 @@ states = {
"UNKNOWN": 3
} # type: Dict[str, int]
def report(state, data, last_check):
# type: (str, str, float) -> None
def report(state: str, data: str, last_check: float) -> None:
print("%s: Last test run completed at %s\n%s" % (
state, time.strftime("%Y-%m-%d %H:%M %Z", time.gmtime(last_check)),
data))