Tue, 08 Nov 2022 19:47:11 +0100
Changed typing completer imports to use importlib.import_module().
--- a/src/eric7/QScintilla/TypingCompleters/CompleterPython.py Tue Nov 08 18:18:42 2022 +0100 +++ b/src/eric7/QScintilla/TypingCompleters/CompleterPython.py Tue Nov 08 19:47:11 2022 +0100 @@ -472,3 +472,17 @@ quoted string (boolean) """ return self.editor.currentStyle() == QsciLexerPython.TripleSingleQuotedString + + +def createCompleter(editor, parent=None): + """ + Function to instantiate a typing completer object. + + @param editor reference to the editor object + @type QScintilla.Editor + @param parent reference to the parent object (defaults to None) + @type QObject (optional) + @return reference to the instantiated typing completer object + @rtype CompleterPython + """ + return CompleterPython(editor, parent=parent)
--- a/src/eric7/QScintilla/TypingCompleters/CompleterRuby.py Tue Nov 08 18:18:42 2022 +0100 +++ b/src/eric7/QScintilla/TypingCompleters/CompleterRuby.py Tue Nov 08 19:47:11 2022 +0100 @@ -207,3 +207,17 @@ (boolean) """ return self.editor.currentStyle() == QsciLexerRuby.POD + + +def createCompleter(editor, parent=None): + """ + Function to instantiate a typing completer object. + + @param editor reference to the editor object + @type QScintilla.Editor + @param parent reference to the parent object (defaults to None) + @type QObject (optional) + @return reference to the instantiated typing completer object + @rtype CompleterRuby + """ + return CompleterRuby(editor, parent=parent)
--- a/src/eric7/QScintilla/TypingCompleters/CompleterYaml.py Tue Nov 08 18:18:42 2022 +0100 +++ b/src/eric7/QScintilla/TypingCompleters/CompleterYaml.py Tue Nov 08 19:47:11 2022 +0100 @@ -161,3 +161,17 @@ return True col -= 1 return False + + +def createCompleter(editor, parent=None): + """ + Function to instantiate a typing completer object. + + @param editor reference to the editor object + @type QScintilla.Editor + @param parent reference to the parent object (defaults to None) + @type QObject (optional) + @return reference to the instantiated typing completer object + @rtype CompleterYaml + """ + return CompleterYaml(editor, parent=parent)
--- a/src/eric7/QScintilla/TypingCompleters/__init__.py Tue Nov 08 18:18:42 2022 +0100 +++ b/src/eric7/QScintilla/TypingCompleters/__init__.py Tue Nov 08 19:47:11 2022 +0100 @@ -7,6 +7,8 @@ Package implementing lexers for the various supported programming languages. """ +import importlib + def getCompleter(language, editor, parent=None): """ @@ -17,20 +19,22 @@ @param parent reference to the parent object (QObject) @return reference to the instanciated lexer object (QsciLexer) """ - try: - if language in ["Python", "Python3", "MicroPython", "Cython"]: - from .CompleterPython import CompleterPython # __IGNORE_WARNING_I101__ - - return CompleterPython(editor, parent) - elif language == "Ruby": - from .CompleterRuby import CompleterRuby # __IGNORE_WARNING_I101__ + languageCompleterMapping = { + "Python": "CompleterPython", + "Python3": "CompleterPython", + "MicroPython": "CompleterPython", + "Cython": "CompleterPython", + "Ruby": "CompleterRuby", + "YAML": "CompleterYaml", + } - return CompleterRuby(editor, parent) - elif language == "YAML": - from .CompleterYaml import CompleterYaml # __IGNORE_WARNING_I101__ + if language in languageCompleterMapping: + mod = importlib.import_module( + "eric7.QScintilla.TypingCompleters.{0}".format( + languageCompleterMapping[language] + ) + ) + if mod: + return mod.createCompleter(editor, parent) - return CompleterYaml(editor, parent) - else: - return None - except ImportError: - return None + return None