tools: Use Python 3 syntax for typing in many files.

This commit is contained in:
rht
2017-11-28 00:24:00 +00:00
committed by Greg Price
parent 5a1869901d
commit 66261f1cc3
17 changed files with 74 additions and 146 deletions

View File

@@ -17,8 +17,7 @@ import lister
from typing import cast, Callable, Dict, Iterator, List
def run_parallel(lint_functions):
# type: (Dict[str, Callable[[], int]]) -> bool
def run_parallel(lint_functions: Dict[str, Callable[[], int]]) -> bool:
pids = []
for name, func in lint_functions.items():
pid = os.fork()
@@ -38,8 +37,7 @@ def run_parallel(lint_functions):
failed = True
return failed
def run():
# type: () -> None
def run() -> None:
parser = argparse.ArgumentParser()
parser.add_argument('--force', default=False,
action="store_true",
@@ -117,13 +115,11 @@ def run():
lint_functions = {} # type: Dict[str, Callable[[], int]]
def lint(func):
# type: (Callable[[], int]) -> Callable[[], int]
def lint(func: Callable[[], int]) -> Callable[[], int]:
lint_functions[func.__name__] = func
return func
def external_linter(name, command, target_langs=[]):
# type: (str, List[str], List[str]) -> None
def external_linter(name: str, command: List[str], target_langs: List[str]=[]) -> None:
"""Registers an external linter program to be run as part of the
linter. This program will be passed the subset of files being
linted that have extensions in target_langs. If there are no
@@ -133,8 +129,7 @@ def run():
"""
color = next(colors)
def run_linter():
# type: () -> int
def run_linter() -> int:
targets = [] # type: List[str]
if len(target_langs) != 0:
targets = [target for lang in target_langs for target in by_lang[lang]]
@@ -172,26 +167,22 @@ def run():
# external_linter('commit_messages', ['tools/commit-message-lint'])
@lint
def custom_py():
# type: () -> int
def custom_py() -> int:
failed = check_custom_checks_py()
return 1 if failed else 0
@lint
def custom_nonpy():
# type: () -> int
def custom_nonpy() -> int:
failed = check_custom_checks_nonpy()
return 1 if failed else 0
@lint
def pyflakes():
# type: () -> int
def pyflakes() -> int:
failed = check_pyflakes(args, by_lang)
return 1 if failed else 0
@lint
def pep8():
# type: () -> int
def pep8() -> int:
failed = check_pep8(by_lang['py'])
return 1 if failed else 0