tools: Add type annotations.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2023-10-25 16:23:54 -07:00
parent a9e3fe9d0c
commit 01d5106e9a
2 changed files with 12 additions and 19 deletions

View file

@ -16,7 +16,7 @@ end_format = "\033[0m"
bold = "\033[1m"
def main():
def main() -> None:
usage = """./tools/provision
Creates a Python virtualenv. Its Python version is equal to
@ -94,7 +94,7 @@ the Python version this command is executed with."""
# In order to install all required packages for the venv, `pip` needs to be executed by
# the venv's Python interpreter. `--prefix venv_dir` ensures that all modules are installed
# in the right place.
def install_dependencies(requirements_filename):
def install_dependencies(requirements_filename: str) -> None:
pip_path = os.path.join(venv_dir, venv_exec_dir, "pip")
# We first install a modern version of pip that supports --prefix
subprocess.call([pip_path, "install", "pip>=10"])

View file

@ -4,9 +4,8 @@ import argparse
import os
import subprocess
import sys
from collections import OrderedDict
from pathlib import PurePath
from typing import Dict, List, cast
from typing import List, OrderedDict
from zulint import lister
@ -25,7 +24,6 @@ exclude = [
# Excluded out of laziness:
"zulip_bots/zulip_bots/simple_lib.py",
"zulip_bots/zulip_bots/tests/test_lib.py",
"tools",
]
# These files will be included even if excluded by a rule above.
@ -93,8 +91,6 @@ force_include = [
"zulip_bots/zulip_bots/bots/susi/test_susi.py",
"zulip_bots/zulip_bots/bots/front/front.py",
"zulip_bots/zulip_bots/bots/front/test_front.py",
"tools/custom_check.py",
"tools/deploy",
]
parser = argparse.ArgumentParser(description="Run mypy on files tracked by git.")
@ -154,9 +150,7 @@ if args.all:
exclude = []
# find all non-excluded files in current directory
files_dict = cast(
Dict[str, List[str]],
lister.list_files(
files_dict = lister.list_files(
targets=args.targets,
ftypes=["py", "pyi"],
use_shebang=True,
@ -164,7 +158,6 @@ files_dict = cast(
exclude=exclude + ["stubs"],
group_by_ftype=True,
extless_only=args.scripts_only,
),
)
for inpath in force_include:
@ -179,7 +172,7 @@ python_files = [
fpath for fpath in files_dict["py"] if not fpath.endswith(".py") or fpath + "i" not in pyi_files
]
repo_python_files = OrderedDict(
repo_python_files = OrderedDict[str, List[str]](
[("zulip", []), ("zulip_bots", []), ("zulip_botserver", []), ("tools", [])]
)
for file_path in python_files: