pre-commit-hooks: python3.6+

This commit is contained in:
Anthony Sottile
2020-02-05 11:10:42 -08:00
parent 551d1a07b3
commit f5c42a050b
60 changed files with 291 additions and 493 deletions

View File

@ -1,7 +1,3 @@
from __future__ import absolute_import
from __future__ import print_function
from __future__ import unicode_literals
import argparse
import collections
from typing import Dict
@ -17,7 +13,7 @@ ALL_ENDINGS = (CR, CRLF, LF)
FIX_TO_LINE_ENDING = {'cr': CR, 'crlf': CRLF, 'lf': LF}
def _fix(filename, contents, ending): # type: (str, bytes, bytes) -> None
def _fix(filename: str, contents: bytes, ending: bytes) -> None:
new_contents = b''.join(
line.rstrip(b'\r\n') + ending for line in contents.splitlines(True)
)
@ -25,11 +21,11 @@ def _fix(filename, contents, ending): # type: (str, bytes, bytes) -> None
f.write(new_contents)
def fix_filename(filename, fix): # type: (str, str) -> int
def fix_filename(filename: str, fix: str) -> int:
with open(filename, 'rb') as f:
contents = f.read()
counts = collections.defaultdict(int) # type: Dict[bytes, int]
counts: Dict[bytes, int] = collections.defaultdict(int)
for line in contents.splitlines(True):
for ending in ALL_ENDINGS:
@ -66,7 +62,7 @@ def fix_filename(filename, fix): # type: (str, str) -> int
return other_endings
def main(argv=None): # type: (Optional[Sequence[str]]) -> int
def main(argv: Optional[Sequence[str]] = None) -> int:
parser = argparse.ArgumentParser()
parser.add_argument(
'-f', '--fix',
@ -81,9 +77,9 @@ def main(argv=None): # type: (Optional[Sequence[str]]) -> int
for filename in args.filenames:
if fix_filename(filename, args.fix):
if args.fix == 'no':
print('{}: mixed line endings'.format(filename))
print(f'{filename}: mixed line endings')
else:
print('{}: fixed mixed line endings'.format(filename))
print(f'{filename}: fixed mixed line endings')
retv = 1
return retv