eric6/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleFixer.py

changeset 8240
93b8a353c4bf
parent 8221
0572a215bd2f
child 8243
cc717c2ae956
--- a/eric6/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleFixer.py	Wed Apr 14 19:38:19 2021 +0200
+++ b/eric6/Plugins/CheckerPlugins/CodeStyleChecker/CodeStyleFixer.py	Wed Apr 14 19:59:16 2021 +0200
@@ -10,14 +10,13 @@
 import os
 import re
 import tokenize
+import contextlib
 from io import StringIO
 
 # CodeStyleCheckerDialog tries to import FixableCodeStyleIssues which fails
 # under Python3. So ignore it.
-try:
+with contextlib.suppress(ImportError):
     import pycodestyle
-except ImportError:
-    pass
 
 FixableCodeStyleIssues = [
     "D111", "D112", "D121", "D131", "D141", "D142",
@@ -209,16 +208,10 @@
                 bfn = '{0}~'.format(os.path.realpath(self.__filename))
             else:
                 bfn = '{0}~'.format(self.__filename)
-            try:
+            with contextlib.suppress(OSError):
                 os.remove(bfn)
-            except OSError:
-                # if there was an error, ignore it
-                pass
-            try:
+            with contextlib.suppress(OSError):
                 os.rename(self.__filename, bfn)
-            except OSError:
-                # if there was an error, ignore it
-                pass
         
         txt = "".join(self.__source)
         try:

eric ide

mercurial