Skip to content

Commit c847dd3

Browse files
authored
Merge pull request #179 from pre-commit/pyupgrade
Add pyupgrade
2 parents a11d931 + 9cee71b commit c847dd3

19 files changed

Lines changed: 33 additions & 29 deletions

.pre-commit-config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,7 @@
2222
hooks:
2323
- id: reorder-python-imports
2424
language_version: python2.7
25+
- repo: https://github.com/asottile/pyupgrade
26+
sha: v1.0.0
27+
hooks:
28+
- id: pyupgrade

pre_commit_hooks/autopep8_wrapper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def main(argv=None):
1717
original_contents = io.open(filename).read()
1818
new_contents = autopep8.fix_code(original_contents, args)
1919
if original_contents != new_contents:
20-
print('Fixing {0}'.format(filename))
20+
print('Fixing {}'.format(filename))
2121
retv = 1
2222
with io.open(filename, 'w') as output_file:
2323
output_file.write(new_contents)

pre_commit_hooks/check_added_large_files.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ def to_file_part(mode, filepart): # pragma: no cover (no git-lfs)
2626
assert mode in ('A', 'R')
2727
return filepart if mode == 'A' else filepart.split(' -> ')[1]
2828

29-
return set(
29+
return {
3030
to_file_part(mode, filepart) for mode, filepart in modes_and_fileparts
3131
if mode in ('A', 'R')
32-
)
32+
}
3333

3434

3535
def find_large_added_files(filenames, maxkb):
@@ -41,7 +41,7 @@ def find_large_added_files(filenames, maxkb):
4141
for filename in filenames:
4242
kb = int(math.ceil(os.stat(filename).st_size / 1024))
4343
if kb > maxkb:
44-
print('{0} ({1} KB) exceeds {2} KB.'.format(filename, kb, maxkb))
44+
print('{} ({} KB) exceeds {} KB.'.format(filename, kb, maxkb))
4545
retv = 1
4646

4747
return retv

pre_commit_hooks/check_ast.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ def check_ast(argv=None):
2222
try:
2323
ast.parse(open(filename, 'rb').read(), filename=filename)
2424
except SyntaxError:
25-
print('{0}: failed parsing with {1}:'.format(
25+
print('{}: failed parsing with {}:'.format(
2626
filename, interpreter,
2727
))
28-
print('\n{0}'.format(
28+
print('\n{}'.format(
2929
' ' + traceback.format_exc().replace('\n', '\n ')
3030
))
3131
retval = 1

pre_commit_hooks/check_byte_order_marker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def main(argv=None):
1616
with open(filename, 'rb') as f:
1717
if f.read(3) == b'\xef\xbb\xbf':
1818
retv = 1
19-
print('{0}: Has a byte-order marker'.format(filename))
19+
print('{}: Has a byte-order marker'.format(filename))
2020

2121
return retv
2222

pre_commit_hooks/check_case_conflict.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
def lower_set(iterable):
12-
return set(x.lower() for x in iterable)
12+
return {x.lower() for x in iterable}
1313

1414

1515
def find_conflicting_filenames(filenames):
@@ -35,7 +35,7 @@ def find_conflicting_filenames(filenames):
3535
if x.lower() in conflicts
3636
]
3737
for filename in sorted(conflicting_files):
38-
print('Case-insensitivity conflict found: {0}'.format(filename))
38+
print('Case-insensitivity conflict found: {}'.format(filename))
3939
retv = 1
4040

4141
return retv

pre_commit_hooks/check_docstring_first.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@ def check_docstring_first(src, filename='<unknown>'):
2727
if tok_type == tokenize.STRING and scol == 0:
2828
if found_docstring_line is not None:
2929
print(
30-
'{0}:{1} Multiple module docstrings '
31-
'(first docstring on line {2}).'.format(
30+
'{}:{} Multiple module docstrings '
31+
'(first docstring on line {}).'.format(
3232
filename, sline, found_docstring_line,
3333
)
3434
)
3535
return 1
3636
elif found_code_line is not None:
3737
print(
38-
'{0}:{1} Module docstring appears after code '
39-
'(code seen on line {2}).'.format(
38+
'{}:{} Module docstring appears after code '
39+
'(code seen on line {}).'.format(
4040
filename, sline, found_code_line,
4141
)
4242
)

pre_commit_hooks/check_json.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def check_json(argv=None):
1616
try:
1717
simplejson.load(open(filename))
1818
except (simplejson.JSONDecodeError, UnicodeDecodeError) as exc:
19-
print('{0}: Failed to json decode ({1})'.format(filename, exc))
19+
print('{}: Failed to json decode ({})'.format(filename, exc))
2020
retval = 1
2121
return retval
2222

pre_commit_hooks/check_symlinks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def check_symlinks(argv=None):
1919
os.path.islink(filename) and
2020
not os.path.exists(filename)
2121
): # pragma: no cover (symlink support required)
22-
print('{0}: Broken symlink'.format(filename))
22+
print('{}: Broken symlink'.format(filename))
2323
retv = 1
2424

2525
return retv

pre_commit_hooks/check_xml.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def check_xml(argv=None):
1919
with io.open(filename, 'rb') as xml_file:
2020
xml.sax.parse(xml_file, xml.sax.ContentHandler())
2121
except xml.sax.SAXException as exc:
22-
print('{0}: Failed to xml parse ({1})'.format(filename, exc))
22+
print('{}: Failed to xml parse ({})'.format(filename, exc))
2323
retval = 1
2424
return retval
2525

0 commit comments

Comments
 (0)