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:
Anders Kaseorg 2020-04-18 15:59:12 -07:00 committed by Tim Abbott
parent 7c5f73dce9
commit 5428c5f296
42 changed files with 311 additions and 577 deletions

View file

@ -12,8 +12,7 @@ EXCLUDED_FILES = [
'zulip/integrations/perforce/git_p4.py',
]
def run():
# type: () -> None
def run() -> None:
parser = argparse.ArgumentParser()
add_default_linter_arguments(parser)
args = parser.parse_args()
@ -27,15 +26,13 @@ def run():
description="Static type checker for Python (config: mypy.ini)")
@linter_config.lint
def custom_py():
# type: () -> int
def custom_py() -> int:
"""Runs custom checks for python files (config: tools/linter_lib/custom_check.py)"""
failed = python_rules.check(by_lang, verbose=args.verbose)
return 1 if failed else 0
@linter_config.lint
def custom_nonpy():
# type: () -> int
def custom_nonpy() -> int:
"""Runs custom checks for non-python files (config: tools/linter_lib/custom_check.py)"""
failed = False
for rule in non_py_rules:
@ -43,8 +40,7 @@ def run():
return 1 if failed else 0
@linter_config.lint
def pep8():
# type: () -> int
def pep8() -> int:
"""Standard Python style linter on 50% of files (config: tools/linter_lib/pep8.py)"""
failed = check_pep8(by_lang['py'])
return 1 if failed else 0

View file

@ -8,11 +8,9 @@ from zulint.printer import print_err, colors
from typing import List
def check_pep8(files):
# type: (List[str]) -> bool
def check_pep8(files: List[str]) -> bool:
def run_pycodestyle(files, ignored_rules):
# type: (List[str], List[str]) -> bool
def run_pycodestyle(files: List[str], ignored_rules: List[str]) -> bool:
failed = False
color = next(colors)
pep8 = subprocess.Popen(

View file

@ -3,36 +3,30 @@
import subprocess
import sys
def exit(message):
# type: (str) -> None
def exit(message: str) -> None:
print('PROBLEM!')
print(message)
sys.exit(1)
def run(command):
# type: (str) -> None
def run(command: str) -> None:
print('\n>>> ' + command)
subprocess.check_call(command.split())
def check_output(command):
# type: (str) -> str
def check_output(command: str) -> str:
return subprocess.check_output(command.split()).decode('ascii')
def get_git_branch():
# type: () -> str
def get_git_branch() -> str:
command = 'git rev-parse --abbrev-ref HEAD'
output = check_output(command)
return output.strip()
def check_git_pristine():
# type: () -> None
def check_git_pristine() -> None:
command = 'git status --porcelain'
output = check_output(command)
if output.strip():
exit('Git is not pristine:\n' + output)
def ensure_on_clean_master():
# type: () -> None
def ensure_on_clean_master() -> None:
branch = get_git_branch()
if branch != 'master':
exit('You are still on a feature branch: %s' % (branch,))
@ -40,8 +34,7 @@ def ensure_on_clean_master():
run('git fetch upstream master')
run('git rebase upstream/master')
def create_pull_branch(pull_id):
# type: (int) -> None
def create_pull_branch(pull_id: int) -> None:
run('git fetch upstream pull/%d/head' % (pull_id,))
run('git checkout -B review-%s FETCH_HEAD' % (pull_id,))
run('git rebase upstream/master')
@ -53,8 +46,7 @@ def create_pull_branch(pull_id):
print(subprocess.check_output(['git', 'log', 'HEAD~..',
'--pretty=format:Author: %an']))
def review_pr():
# type: () -> None
def review_pr() -> None:
try:
pull_id = int(sys.argv[1])
except Exception: