eric6/QScintilla/SpellChecker.py

branch
maintenance
changeset 8273
698ae46f40a4
parent 8043
0acf98cd089a
parent 8243
cc717c2ae956
--- a/eric6/QScintilla/SpellChecker.py	Fri Apr 02 11:59:41 2021 +0200
+++ b/eric6/QScintilla/SpellChecker.py	Sat May 01 14:27:20 2021 +0200
@@ -10,16 +10,15 @@
 """
 
 import os
+import contextlib
 
 from PyQt5.QtCore import QTimer, QObject
 
 import Preferences
 import Utilities
 
-try:
+with contextlib.suppress(ImportError, AttributeError, OSError):
     import enchant
-except (ImportError, AttributeError, OSError):
-    pass
 
 
 class SpellChecker(QObject):
@@ -43,7 +42,7 @@
         @param checkRegion reference to a function to check for a valid
             region
         """
-        super(SpellChecker, self).__init__(editor)
+        super().__init__(editor)
         
         self.editor = editor
         self.indicator = indicator
@@ -66,10 +65,8 @@
         
         @return list of available languages (list of strings)
         """
-        try:
+        with contextlib.suppress(NameError):
             return enchant.list_languages()
-        except NameError:
-            pass
         return []
     
     @classmethod
@@ -80,10 +77,8 @@
         @return flag indicating availability (boolean)
         """
         if Preferences.getEditor("SpellCheckingEnabled"):
-            try:
+            with contextlib.suppress(NameError, AttributeError):
                 return len(enchant.list_languages()) > 0
-            except (NameError, AttributeError):
-                pass
         return False
     
     @classmethod
@@ -433,11 +428,8 @@
         suggestions = []
         spell = self._spelling_dict
         if spell and len(word) >= self.minimumWordSize:
-            try:
+            with contextlib.suppress(enchant.errors.Error):
                 suggestions = spell.suggest(word)
-            except enchant.errors.Error:
-                # ignore these
-                pass
         return suggestions
     
     def add(self, word=None):
@@ -529,12 +521,9 @@
                     (wordEnd - wordStart) >= self.minimumWordSize and
                     self.__checkRegion(wordStart)
                 ):
-                    try:
+                    with contextlib.suppress(enchant.errors.Error):
                         if spell.check(word):
                             continue
-                    except enchant.errors.Error:
-                        # ignore these
-                        pass
                     if word in self.__ignoreWords:
                         continue
                     self.word = word

eric ide

mercurial