mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-03-29 18:16:52 +00:00
Fix resource warnings
This commit is contained in:
parent
a193eab99e
commit
5dc306b35d
7 changed files with 14 additions and 7 deletions
|
|
@ -14,7 +14,8 @@ def main(argv=None):
|
|||
|
||||
retv = 0
|
||||
for filename in args.files:
|
||||
original_contents = io.open(filename, encoding='UTF-8').read()
|
||||
with io.open(filename, encoding='UTF-8') as f:
|
||||
original_contents = f.read()
|
||||
new_contents = autopep8.fix_code(original_contents, args)
|
||||
if original_contents != new_contents:
|
||||
print('Fixing {}'.format(filename))
|
||||
|
|
|
|||
|
|
@ -18,7 +18,8 @@ def check_ast(argv=None):
|
|||
for filename in args.filenames:
|
||||
|
||||
try:
|
||||
ast.parse(open(filename, 'rb').read(), filename=filename)
|
||||
with open(filename, 'rb') as f:
|
||||
ast.parse(f.read(), filename=filename)
|
||||
except SyntaxError:
|
||||
print('{}: failed parsing with {} {}:'.format(
|
||||
filename,
|
||||
|
|
|
|||
|
|
@ -47,7 +47,8 @@ class BuiltinTypeVisitor(ast.NodeVisitor):
|
|||
|
||||
|
||||
def check_file_for_builtin_type_constructors(filename, ignore=None, allow_dict_kwargs=True):
|
||||
tree = ast.parse(open(filename, 'rb').read(), filename=filename)
|
||||
with open(filename, 'rb') as f:
|
||||
tree = ast.parse(f.read(), filename=filename)
|
||||
visitor = BuiltinTypeVisitor(ignore=ignore, allow_dict_kwargs=allow_dict_kwargs)
|
||||
visitor.visit(tree)
|
||||
return visitor.builtin_type_calls
|
||||
|
|
|
|||
|
|
@ -58,7 +58,8 @@ def main(argv=None):
|
|||
retv = 0
|
||||
|
||||
for filename in args.filenames:
|
||||
contents = io.open(filename, encoding='UTF-8').read()
|
||||
with io.open(filename, encoding='UTF-8') as f:
|
||||
contents = f.read()
|
||||
retv |= check_docstring_first(contents, filename=filename)
|
||||
|
||||
return retv
|
||||
|
|
|
|||
|
|
@ -36,7 +36,8 @@ class DebugStatementParser(ast.NodeVisitor):
|
|||
|
||||
def check_file(filename):
|
||||
try:
|
||||
ast_obj = ast.parse(open(filename, 'rb').read(), filename=filename)
|
||||
with open(filename, 'rb') as f:
|
||||
ast_obj = ast.parse(f.read(), filename=filename)
|
||||
except SyntaxError:
|
||||
print('{} - Could not parse ast'.format(filename))
|
||||
print()
|
||||
|
|
|
|||
|
|
@ -32,7 +32,8 @@ def get_line_offsets_by_line_no(src):
|
|||
|
||||
|
||||
def fix_strings(filename):
|
||||
contents = io.open(filename, encoding='UTF-8').read()
|
||||
with io.open(filename, encoding='UTF-8') as f:
|
||||
contents = f.read()
|
||||
line_offsets = get_line_offsets_by_line_no(contents)
|
||||
|
||||
# Basically a mutable string
|
||||
|
|
|
|||
|
|
@ -94,7 +94,8 @@ def test_dict_no_allow_kwargs_exprs(expression, calls):
|
|||
|
||||
def test_ignore_constructors():
|
||||
visitor = BuiltinTypeVisitor(ignore=('complex', 'dict', 'float', 'int', 'list', 'str', 'tuple'))
|
||||
visitor.visit(ast.parse(open(get_resource_path('builtin_constructors.py'), 'rb').read(), 'builtin_constructors.py'))
|
||||
with open(get_resource_path('builtin_constructors.py'), 'rb') as f:
|
||||
visitor.visit(ast.parse(f.read(), 'builtin_constructors.py'))
|
||||
assert visitor.builtin_type_calls == []
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue