eric6/QScintilla/SpellChecker.py

changeset 8243
cc717c2ae956
parent 8218
7c09585bd960
child 8273
698ae46f40a4
diff -r aa713ac50c0d -r cc717c2ae956 eric6/QScintilla/SpellChecker.py
--- a/eric6/QScintilla/SpellChecker.py	Thu Apr 15 16:52:05 2021 +0200
+++ b/eric6/QScintilla/SpellChecker.py	Thu Apr 15 18:11:24 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):
@@ -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