Commit a90f311d authored by Victor Stinner's avatar Victor Stinner

Cleanup findnocoding.py and pysource.py scripts (with infile/infile.close)

parent 98516a69
...@@ -60,7 +60,6 @@ def needs_declaration(fullpath): ...@@ -60,7 +60,6 @@ def needs_declaration(fullpath):
if get_declaration(line1) or get_declaration(line2): if get_declaration(line1) or get_declaration(line2):
# the file does have an encoding declaration, so trust it # the file does have an encoding declaration, so trust it
infile.close()
return False return False
# check the whole file for non utf-8 characters # check the whole file for non utf-8 characters
......
...@@ -55,8 +55,8 @@ def looks_like_python(fullpath): ...@@ -55,8 +55,8 @@ def looks_like_python(fullpath):
if infile is None: if infile is None:
return False return False
line = infile.readline() with infile:
infile.close() line = infile.readline()
if binary_re.search(line): if binary_re.search(line):
# file appears to be binary # file appears to be binary
...@@ -76,8 +76,8 @@ def can_be_compiled(fullpath): ...@@ -76,8 +76,8 @@ def can_be_compiled(fullpath):
if infile is None: if infile is None:
return False return False
code = infile.read() with infile:
infile.close() code = infile.read()
try: try:
compile(code, fullpath, "exec") compile(code, fullpath, "exec")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment