Apply typing to all of pre-commit-hooks

This commit is contained in:
Anthony Sottile
2019-01-31 19:19:10 -08:00
parent 63cc3414e9
commit 030bfac7e4
54 changed files with 401 additions and 264 deletions

View File

@ -3,23 +3,25 @@ from __future__ import print_function
from __future__ import unicode_literals
import subprocess
from typing import Any
from typing import Set
class CalledProcessError(RuntimeError):
pass
def added_files():
def added_files(): # type: () -> Set[str]
return set(cmd_output(
'git', 'diff', '--staged', '--name-only', '--diff-filter=A',
).splitlines())
def cmd_output(*cmd, **kwargs):
def cmd_output(*cmd, **kwargs): # type: (*str, **Any) -> str
retcode = kwargs.pop('retcode', 0)
popen_kwargs = {'stdout': subprocess.PIPE, 'stderr': subprocess.PIPE}
popen_kwargs.update(kwargs)
proc = subprocess.Popen(cmd, **popen_kwargs)
kwargs.setdefault('stdout', subprocess.PIPE)
kwargs.setdefault('stderr', subprocess.PIPE)
proc = subprocess.Popen(cmd, **kwargs)
stdout, stderr = proc.communicate()
stdout = stdout.decode('UTF-8')
if stderr is not None: