--- a/eric6/QScintilla/Lexers/LexerPygments.py Wed Apr 14 19:38:19 2021 +0200 +++ b/eric6/QScintilla/Lexers/LexerPygments.py Wed Apr 14 19:59:16 2021 +0200 @@ -7,6 +7,8 @@ Module implementing a custom lexer using pygments. """ +import contextlib + from pygments.token import Token from pygments.lexers import ( guess_lexer_for_filename, guess_lexer, find_lexer_class @@ -453,17 +455,13 @@ if self.editor is not None: fn = self.editor.getFileName() if fn: - try: + with contextlib.suppress(ClassNotFound): lexer = guess_lexer_for_filename(fn, text) - except ClassNotFound: - pass # step 2: guess on text only if lexer is None: - try: + with contextlib.suppress(ClassNotFound): lexer = guess_lexer(text) - except ClassNotFound: - pass return lexer