pre-commit-hooks: python3.6+
diff --git a/pre_commit_hooks/check_added_large_files.py b/pre_commit_hooks/check_added_large_files.py
index be39498..91f5754 100644
--- a/pre_commit_hooks/check_added_large_files.py
+++ b/pre_commit_hooks/check_added_large_files.py
@@ -1,13 +1,7 @@
-from __future__ import absolute_import
-from __future__ import division
-from __future__ import print_function
-from __future__ import unicode_literals
-
import argparse
import json
import math
import os
-from typing import Iterable
from typing import Optional
from typing import Sequence
from typing import Set
@@ -17,7 +11,7 @@
from pre_commit_hooks.util import cmd_output
-def lfs_files(): # type: () -> Set[str]
+def lfs_files() -> Set[str]:
try:
# Introduced in git-lfs 2.2.0, first working in 2.2.1
lfs_ret = cmd_output('git', 'lfs', 'status', '--json')
@@ -27,23 +21,20 @@
return set(json.loads(lfs_ret)['files'])
-def find_large_added_files(filenames, maxkb):
- # type: (Iterable[str], int) -> int
+def find_large_added_files(filenames: Sequence[str], maxkb: int) -> int:
# Find all added files that are also in the list of files pre-commit tells
# us about
- filenames = (added_files() & set(filenames)) - lfs_files()
-
retv = 0
- for filename in filenames:
+ for filename in (added_files() & set(filenames)) - lfs_files():
kb = int(math.ceil(os.stat(filename).st_size / 1024))
if kb > maxkb:
- print('{} ({} KB) exceeds {} KB.'.format(filename, kb, maxkb))
+ print(f'{filename} ({kb} KB) exceeds {maxkb} KB.')
retv = 1
return retv
-def main(argv=None): # type: (Optional[Sequence[str]]) -> int
+def main(argv: Optional[Sequence[str]] = None) -> int:
parser = argparse.ArgumentParser()
parser.add_argument(
'filenames', nargs='*',