Add pyupgrade
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a3bb7a4..ccfdc4b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml
@@ -22,3 +22,7 @@ hooks: - id: reorder-python-imports language_version: python2.7 +- repo: https://github.com/asottile/pyupgrade + sha: v1.0.0 + hooks: + - id: pyupgrade
diff --git a/pre_commit_hooks/autopep8_wrapper.py b/pre_commit_hooks/autopep8_wrapper.py index f6f55fb..52aaebe 100644 --- a/pre_commit_hooks/autopep8_wrapper.py +++ b/pre_commit_hooks/autopep8_wrapper.py
@@ -17,7 +17,7 @@ original_contents = io.open(filename).read() new_contents = autopep8.fix_code(original_contents, args) if original_contents != new_contents: - print('Fixing {0}'.format(filename)) + print('Fixing {}'.format(filename)) retv = 1 with io.open(filename, 'w') as output_file: output_file.write(new_contents)
diff --git a/pre_commit_hooks/check_added_large_files.py b/pre_commit_hooks/check_added_large_files.py index 5ef7f22..8d5f4c4 100644 --- a/pre_commit_hooks/check_added_large_files.py +++ b/pre_commit_hooks/check_added_large_files.py
@@ -26,10 +26,10 @@ assert mode in ('A', 'R') return filepart if mode == 'A' else filepart.split(' -> ')[1] - return set( + return { to_file_part(mode, filepart) for mode, filepart in modes_and_fileparts if mode in ('A', 'R') - ) + } def find_large_added_files(filenames, maxkb): @@ -41,7 +41,7 @@ for filename in filenames: kb = int(math.ceil(os.stat(filename).st_size / 1024)) if kb > maxkb: - print('{0} ({1} KB) exceeds {2} KB.'.format(filename, kb, maxkb)) + print('{} ({} KB) exceeds {} KB.'.format(filename, kb, maxkb)) retv = 1 return retv
diff --git a/pre_commit_hooks/check_ast.py b/pre_commit_hooks/check_ast.py index c993e6a..169e077 100644 --- a/pre_commit_hooks/check_ast.py +++ b/pre_commit_hooks/check_ast.py
@@ -22,10 +22,10 @@ try: ast.parse(open(filename, 'rb').read(), filename=filename) except SyntaxError: - print('{0}: failed parsing with {1}:'.format( + print('{}: failed parsing with {}:'.format( filename, interpreter, )) - print('\n{0}'.format( + print('\n{}'.format( ' ' + traceback.format_exc().replace('\n', '\n ') )) retval = 1
diff --git a/pre_commit_hooks/check_byte_order_marker.py b/pre_commit_hooks/check_byte_order_marker.py index 274f949..1541b30 100644 --- a/pre_commit_hooks/check_byte_order_marker.py +++ b/pre_commit_hooks/check_byte_order_marker.py
@@ -16,7 +16,7 @@ with open(filename, 'rb') as f: if f.read(3) == b'\xef\xbb\xbf': retv = 1 - print('{0}: Has a byte-order marker'.format(filename)) + print('{}: Has a byte-order marker'.format(filename)) return retv
diff --git a/pre_commit_hooks/check_case_conflict.py b/pre_commit_hooks/check_case_conflict.py index dd4ad86..3d6cf74 100644 --- a/pre_commit_hooks/check_case_conflict.py +++ b/pre_commit_hooks/check_case_conflict.py
@@ -9,7 +9,7 @@ def lower_set(iterable): - return set(x.lower() for x in iterable) + return {x.lower() for x in iterable} def find_conflicting_filenames(filenames): @@ -35,7 +35,7 @@ if x.lower() in conflicts ] for filename in sorted(conflicting_files): - print('Case-insensitivity conflict found: {0}'.format(filename)) + print('Case-insensitivity conflict found: {}'.format(filename)) retv = 1 return retv
diff --git a/pre_commit_hooks/check_docstring_first.py b/pre_commit_hooks/check_docstring_first.py index da5425d..8e658a1 100644 --- a/pre_commit_hooks/check_docstring_first.py +++ b/pre_commit_hooks/check_docstring_first.py
@@ -27,16 +27,16 @@ if tok_type == tokenize.STRING and scol == 0: if found_docstring_line is not None: print( - '{0}:{1} Multiple module docstrings ' - '(first docstring on line {2}).'.format( + '{}:{} Multiple module docstrings ' + '(first docstring on line {}).'.format( filename, sline, found_docstring_line, ) ) return 1 elif found_code_line is not None: print( - '{0}:{1} Module docstring appears after code ' - '(code seen on line {2}).'.format( + '{}:{} Module docstring appears after code ' + '(code seen on line {}).'.format( filename, sline, found_code_line, ) )
diff --git a/pre_commit_hooks/check_json.py b/pre_commit_hooks/check_json.py index 688f719..e1578ff 100644 --- a/pre_commit_hooks/check_json.py +++ b/pre_commit_hooks/check_json.py
@@ -16,7 +16,7 @@ try: simplejson.load(open(filename)) except (simplejson.JSONDecodeError, UnicodeDecodeError) as exc: - print('{0}: Failed to json decode ({1})'.format(filename, exc)) + print('{}: Failed to json decode ({})'.format(filename, exc)) retval = 1 return retval
diff --git a/pre_commit_hooks/check_symlinks.py b/pre_commit_hooks/check_symlinks.py index 713dd83..fd80089 100644 --- a/pre_commit_hooks/check_symlinks.py +++ b/pre_commit_hooks/check_symlinks.py
@@ -19,7 +19,7 @@ os.path.islink(filename) and not os.path.exists(filename) ): # pragma: no cover (symlink support required) - print('{0}: Broken symlink'.format(filename)) + print('{}: Broken symlink'.format(filename)) retv = 1 return retv
diff --git a/pre_commit_hooks/check_xml.py b/pre_commit_hooks/check_xml.py index 926f6e9..a4c11a5 100644 --- a/pre_commit_hooks/check_xml.py +++ b/pre_commit_hooks/check_xml.py
@@ -19,7 +19,7 @@ with io.open(filename, 'rb') as xml_file: xml.sax.parse(xml_file, xml.sax.ContentHandler()) except xml.sax.SAXException as exc: - print('{0}: Failed to xml parse ({1})'.format(filename, exc)) + print('{}: Failed to xml parse ({})'.format(filename, exc)) retval = 1 return retval
diff --git a/pre_commit_hooks/debug_statement_hook.py b/pre_commit_hooks/debug_statement_hook.py index 52fe72e..902198f 100644 --- a/pre_commit_hooks/debug_statement_hook.py +++ b/pre_commit_hooks/debug_statement_hook.py
@@ -7,7 +7,7 @@ import traceback -DEBUG_STATEMENTS = set(['pdb', 'ipdb', 'pudb', 'q', 'rdb']) +DEBUG_STATEMENTS = {'pdb', 'ipdb', 'pudb', 'q', 'rdb'} DebugStatement = collections.namedtuple( @@ -37,7 +37,7 @@ try: ast_obj = ast.parse(open(filename).read(), filename=filename) except SyntaxError: - print('{0} - Could not parse ast'.format(filename)) + print('{} - Could not parse ast'.format(filename)) print() print('\t' + traceback.format_exc().replace('\n', '\n\t')) print() @@ -47,7 +47,7 @@ if visitor.debug_import_statements: for debug_statement in visitor.debug_import_statements: print( - '{0}:{1}:{2} - {3} imported'.format( + '{}:{}:{} - {} imported'.format( filename, debug_statement.line, debug_statement.col,
diff --git a/pre_commit_hooks/detect_private_key.py b/pre_commit_hooks/detect_private_key.py index d187364..feb2208 100644 --- a/pre_commit_hooks/detect_private_key.py +++ b/pre_commit_hooks/detect_private_key.py
@@ -26,7 +26,7 @@ if private_key_files: for private_key_file in private_key_files: - print('Private key found: {0}'.format(private_key_file)) + print('Private key found: {}'.format(private_key_file)) return 1 else: return 0
diff --git a/pre_commit_hooks/end_of_file_fixer.py b/pre_commit_hooks/end_of_file_fixer.py index 3349d83..4fe82b7 100644 --- a/pre_commit_hooks/end_of_file_fixer.py +++ b/pre_commit_hooks/end_of_file_fixer.py
@@ -58,7 +58,7 @@ with open(filename, 'rb+') as file_obj: ret_for_file = fix_file(file_obj) if ret_for_file: - print('Fixing {0}'.format(filename)) + print('Fixing {}'.format(filename)) retv |= ret_for_file return retv
diff --git a/pre_commit_hooks/pretty_format_json.py b/pre_commit_hooks/pretty_format_json.py index 91dae8d..bf1ccb1 100644 --- a/pre_commit_hooks/pretty_format_json.py +++ b/pre_commit_hooks/pretty_format_json.py
@@ -25,7 +25,7 @@ def _autofix(filename, new_contents): - print("Fixing file {0}".format(filename)) + print("Fixing file {}".format(filename)) with open(filename, 'w') as f: f.write(new_contents) @@ -100,7 +100,7 @@ ) if contents != pretty_contents: - print("File {0} is not pretty-formatted".format(json_file)) + print("File {} is not pretty-formatted".format(json_file)) if args.autofix: _autofix(json_file, pretty_contents) @@ -109,7 +109,7 @@ except simplejson.JSONDecodeError: print( - "Input File {0} is not a valid JSON, consider using check-json" + "Input File {} is not a valid JSON, consider using check-json" .format(json_file) ) return 1
diff --git a/pre_commit_hooks/requirements_txt_fixer.py b/pre_commit_hooks/requirements_txt_fixer.py index 64b5e47..efa1906 100644 --- a/pre_commit_hooks/requirements_txt_fixer.py +++ b/pre_commit_hooks/requirements_txt_fixer.py
@@ -84,7 +84,7 @@ ret_for_file = fix_requirements(file_obj) if ret_for_file: - print('Sorting {0}'.format(arg)) + print('Sorting {}'.format(arg)) retv |= ret_for_file
diff --git a/pre_commit_hooks/string_fixer.py b/pre_commit_hooks/string_fixer.py index 9ef7a37..3523e8a 100644 --- a/pre_commit_hooks/string_fixer.py +++ b/pre_commit_hooks/string_fixer.py
@@ -69,7 +69,7 @@ for filename in args.filenames: return_value = fix_strings(filename) if return_value != 0: - print('Fixing strings in {0}'.format(filename)) + print('Fixing strings in {}'.format(filename)) retv |= return_value return retv
diff --git a/pre_commit_hooks/tests_should_end_in_test.py b/pre_commit_hooks/tests_should_end_in_test.py index 4bfc767..5f4cd08 100644 --- a/pre_commit_hooks/tests_should_end_in_test.py +++ b/pre_commit_hooks/tests_should_end_in_test.py
@@ -26,7 +26,7 @@ ): retcode = 1 print( - '{0} does not match pattern "{1}"'.format( + '{} does not match pattern "{}"'.format( filename, test_name_pattern ) )
diff --git a/pre_commit_hooks/trailing_whitespace_fixer.py b/pre_commit_hooks/trailing_whitespace_fixer.py index d23d58d..1ae15a9 100644 --- a/pre_commit_hooks/trailing_whitespace_fixer.py +++ b/pre_commit_hooks/trailing_whitespace_fixer.py
@@ -67,7 +67,7 @@ for ext in md_exts: if any(c in ext[1:] for c in r'./\:'): parser.error( - "bad --markdown-linebreak-ext extension '{0}' (has . / \\ :)\n" + "bad --markdown-linebreak-ext extension '{}' (has . / \\ :)\n" " (probably filename; use '--markdown-linebreak-ext=EXT')" .format(ext) )
diff --git a/tests/readme_test.py b/tests/readme_test.py index d479d42..4d4c972 100644 --- a/tests/readme_test.py +++ b/tests/readme_test.py
@@ -10,4 +10,4 @@ readme_contents = io.open('README.md').read() hooks = yaml.load(io.open('hooks.yaml').read()) for hook in hooks: - assert '`{0}`'.format(hook['id']) in readme_contents + assert '`{}`'.format(hook['id']) in readme_contents