eric6/Plugins/CheckerPlugins/CodeStyleChecker/PathLib/PathlibChecker.py

changeset 8243
cc717c2ae956
parent 8218
7c09585bd960
diff -r aa713ac50c0d -r cc717c2ae956 eric6/Plugins/CheckerPlugins/CodeStyleChecker/PathLib/PathlibChecker.py
--- a/eric6/Plugins/CheckerPlugins/CodeStyleChecker/PathLib/PathlibChecker.py	Thu Apr 15 16:52:05 2021 +0200
+++ b/eric6/Plugins/CheckerPlugins/CodeStyleChecker/PathLib/PathlibChecker.py	Thu Apr 15 18:11:24 2021 +0200
@@ -10,6 +10,7 @@
 
 import ast
 import copy
+import contextlib
 
 
 class PathlibChecker:
@@ -177,12 +178,9 @@
         @param name resolved name of the node
         @type str
         """
-        try:
+        with contextlib.suppress(KeyError):
             errorCode = self.Function2Code[name]
             self.__error(node.lineno - 1, node.col_offset, errorCode)
-        except KeyError:
-            # name is not in our list of replacements
-            pass
 
 
 class PathlibVisitor(ast.NodeVisitor):
@@ -260,12 +258,10 @@
         @return resolved name
         @rtype str
         """
-        try:
+        with contextlib.suppress(KeyError, IndexError):
             attr = self.__importAlias[self.__names[-1]]
             self.__names[-1] = attr
-        except (KeyError, IndexError):
             # do nothing if there is no such name or the names list is empty
-            pass
         
         return ".".join(reversed(self.__names))
     

eric ide

mercurial