From: Victor Stinner Date: Wed, 1 Aug 2012 22:05:41 +0000 (+0200) Subject: Cleanup findnocoding.py and pysource.py scripts (with infile/infile.close) X-Git-Tag: v3.3.0b2~67 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a90f311d0592f6ab56068441413a1925bd7393f4;p=python Cleanup findnocoding.py and pysource.py scripts (with infile/infile.close) --- diff --git a/Tools/scripts/findnocoding.py b/Tools/scripts/findnocoding.py index d6643860a2..b3e9dc7361 100755 --- a/Tools/scripts/findnocoding.py +++ b/Tools/scripts/findnocoding.py @@ -60,7 +60,6 @@ def needs_declaration(fullpath): if get_declaration(line1) or get_declaration(line2): # the file does have an encoding declaration, so trust it - infile.close() return False # check the whole file for non utf-8 characters diff --git a/Tools/scripts/pysource.py b/Tools/scripts/pysource.py index 7348a68f21..69e8e0df4f 100755 --- a/Tools/scripts/pysource.py +++ b/Tools/scripts/pysource.py @@ -55,8 +55,8 @@ def looks_like_python(fullpath): if infile is None: return False - line = infile.readline() - infile.close() + with infile: + line = infile.readline() if binary_re.search(line): # file appears to be binary @@ -76,8 +76,8 @@ def can_be_compiled(fullpath): if infile is None: return False - code = infile.read() - infile.close() + with infile: + code = infile.read() try: compile(code, fullpath, "exec")