Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a90f311

Browse files
committed
Cleanup findnocoding.py and pysource.py scripts (with infile/infile.close)
1 parent 98516a6 commit a90f311

2 files changed

Lines changed: 4 additions & 5 deletions

File tree

Tools/scripts/findnocoding.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ def needs_declaration(fullpath):
6060

6161
if get_declaration(line1) or get_declaration(line2):
6262
# the file does have an encoding declaration, so trust it
63-
infile.close()
6463
return False
6564

6665
# check the whole file for non utf-8 characters

Tools/scripts/pysource.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ def looks_like_python(fullpath):
5555
if infile is None:
5656
return False
5757

58-
line = infile.readline()
59-
infile.close()
58+
with infile:
59+
line = infile.readline()
6060

6161
if binary_re.search(line):
6262
# file appears to be binary
@@ -76,8 +76,8 @@ def can_be_compiled(fullpath):
7676
if infile is None:
7777
return False
7878

79-
code = infile.read()
80-
infile.close()
79+
with infile:
80+
code = infile.read()
8181

8282
try:
8383
compile(code, fullpath, "exec")

0 commit comments

Comments
 (0)