mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-06 12:06:53 +00:00
Apply typing to all of pre-commit-hooks
This commit is contained in:
parent
63cc3414e9
commit
030bfac7e4
54 changed files with 401 additions and 264 deletions
|
|
@ -4,6 +4,9 @@ from __future__ import unicode_literals
|
|||
|
||||
import argparse
|
||||
import collections
|
||||
from typing import Dict
|
||||
from typing import Optional
|
||||
from typing import Sequence
|
||||
|
||||
|
||||
CRLF = b'\r\n'
|
||||
|
|
@ -14,7 +17,7 @@ ALL_ENDINGS = (CR, CRLF, LF)
|
|||
FIX_TO_LINE_ENDING = {'cr': CR, 'crlf': CRLF, 'lf': LF}
|
||||
|
||||
|
||||
def _fix(filename, contents, ending):
|
||||
def _fix(filename, contents, ending): # type: (str, bytes, bytes) -> None
|
||||
new_contents = b''.join(
|
||||
line.rstrip(b'\r\n') + ending for line in contents.splitlines(True)
|
||||
)
|
||||
|
|
@ -22,11 +25,11 @@ def _fix(filename, contents, ending):
|
|||
f.write(new_contents)
|
||||
|
||||
|
||||
def fix_filename(filename, fix):
|
||||
def fix_filename(filename, fix): # type: (str, str) -> int
|
||||
with open(filename, 'rb') as f:
|
||||
contents = f.read()
|
||||
|
||||
counts = collections.defaultdict(int)
|
||||
counts = collections.defaultdict(int) # type: Dict[bytes, int]
|
||||
|
||||
for line in contents.splitlines(True):
|
||||
for ending in ALL_ENDINGS:
|
||||
|
|
@ -63,7 +66,7 @@ def fix_filename(filename, fix):
|
|||
return other_endings
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
def main(argv=None): # type: (Optional[Sequence[str]]) -> int
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument(
|
||||
'-f', '--fix',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue