Changed code to use the 'open()' context manager. release-7.1.1

Wed, 14 Oct 2020 19:46:35 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 14 Oct 2020 19:46:35 +0200
changeset 89
8acd446fb6e6
parent 88
db1f004f14ca
child 90
0cc79542c127

Changed code to use the 'open()' context manager.

ChangeLog file | annotate | diff | comparison | revisions
PluginPyLint.py file | annotate | diff | comparison | revisions
PluginPyLint.zip file | annotate | diff | comparison | revisions
PyLint/PyLintExecDialog.py file | annotate | diff | comparison | revisions
--- a/ChangeLog	Wed Oct 07 19:33:10 2020 +0200
+++ b/ChangeLog	Wed Oct 14 19:46:35 2020 +0200
@@ -1,5 +1,8 @@
 ChangeLog
 ---------
+Version 7.1.1:
+- changed code to use the 'open()' context manager
+
 Version 7.1.0:
 - changed exec_() into exec()
 
--- a/PluginPyLint.py	Wed Oct 07 19:33:10 2020 +0200
+++ b/PluginPyLint.py	Wed Oct 14 19:46:35 2020 +0200
@@ -29,7 +29,7 @@
 author = "Detlev Offenbach <detlev@die-offenbachs.de>"
 autoactivate = True
 deactivateable = True
-version = "7.1.0"
+version = "7.1.1"
 className = "PyLintPlugin"
 packageName = "PyLint"
 shortDescription = "Show the PyLint dialogs."
@@ -219,20 +219,17 @@
         _exePy3 = set()
         versionArgs = ["-c", "import sys; print(sys.version_info[0])"]
         for exe in exes:
-            try:
-                f = open(exe, "r")
+            with open(exe, "r") as f:
                 line0 = f.readline()
-                program = line0.replace("#!", "").strip()
-                process = QProcess()
-                process.start(program, versionArgs)
-                process.waitForFinished(5000)
-                # get a QByteArray of the output
-                versionBytes = process.readAllStandardOutput()
-                versionStr = str(versionBytes, encoding='utf-8').strip()
-                if versionStr == "3":
-                    _exePy3.add(exe)
-            finally:
-                f.close()
+            program = line0.replace("#!", "").strip()
+            process = QProcess()
+            process.start(program, versionArgs)
+            process.waitForFinished(5000)
+            # get a QByteArray of the output
+            versionBytes = process.readAllStandardOutput()
+            versionStr = str(versionBytes, encoding='utf-8').strip()
+            if versionStr == "3":
+                _exePy3.add(exe)
         
         executables = _exePy3
     
Binary file PluginPyLint.zip has changed
--- a/PyLint/PyLintExecDialog.py	Wed Oct 07 19:33:10 2020 +0200
+++ b/PyLint/PyLintExecDialog.py	Wed Oct 14 19:46:35 2020 +0200
@@ -378,10 +378,9 @@
         
         try:
             import codecs
-            f = open(self.reportFile, 'wb')
-            f.write(codecs.BOM_UTF8)
-            f.write(self.buf.encode('utf-8'))
-            f.close()
+            with open(self.reportFile, 'wb') as f:
+                f.write(codecs.BOM_UTF8)
+                f.write(self.buf.encode('utf-8'))
         except IOError as why:
             E5MessageBox.critical(
                 self, self.tr('PyLint Report'),

eric ide

mercurial