diff -r e9e7eca7efee -r bf71ee032bb4 src/eric7/QScintilla/DocstringGenerator/BaseDocstringGenerator.py --- a/src/eric7/QScintilla/DocstringGenerator/BaseDocstringGenerator.py Wed Jul 13 11:16:20 2022 +0200 +++ b/src/eric7/QScintilla/DocstringGenerator/BaseDocstringGenerator.py Wed Jul 13 14:55:47 2022 +0200 @@ -20,15 +20,15 @@ def getIndentStr(text): """ Function to get the indentation of a text. - + @param text text to extract indentation from @type str @return indentation string @rtype str """ - indent = '' + indent = "" - ret = re.match(r'(\s*)', text) + ret = re.match(r"(\s*)", text) if ret: indent = ret.group(1) @@ -39,20 +39,21 @@ """ Class implementing a docstring generator base class. """ + def __init__(self, editor): """ Constructor - + @param editor reference to the editor widget @type Editor """ self.editor = editor - + def isFunctionStart(self, text): """ Public method to test, if a text is the start of a function or method definition. - + @param text line of text to be tested @type str @return flag indicating that the given text starts a function or @@ -60,36 +61,36 @@ @rtype bool """ return False - + def hasFunctionDefinition(self, cursorPosition): """ Public method to test, if the cursor is right below a function definition. - + @param cursorPosition current cursor position (line and column) @type tuple of (int, int) @return flag indicating cursor is right below a function definition @rtype bool """ return False - + def isDocstringIntro(self, cursorPosition): """ Public function to test, if the line up to the cursor position might be introducing a docstring. - + @param cursorPosition current cursor position (line and column) @type tuple of (int, int) @return flag indicating a potential start of a docstring @rtype bool """ return False - + def insertDocstring(self, cursorPosition, fromStart=True): """ Public method to insert a docstring for the function at the cursor position. - + @param cursorPosition position of the cursor (line and index) @type tuple of (int, int) @param fromStart flag indicating that the editor text cursor is placed @@ -98,47 +99,43 @@ """ # just do nothing in the base class return - + def insertDocstringFromShortcut(self, cursorPosition): """ Public method to insert a docstring for the function at the cursor position initiated via a keyboard shortcut. - + @param cursorPosition position of the cursor (line and index) @type tuple of (int, int) """ # just do nothing in the base class return - + def getDocstringType(self): """ Public method to determine the docstring type to be generated. - + @return docstring type (one of 'ericdoc', 'numpydoc', 'googledoc', 'sphinxdoc') @rtype str """ docstringStyle = "" - + project = ericApp().getObject("Project") filename = self.editor.getFileName() - if ( - filename and - project.isOpen() and - project.isProjectFile(filename) - ): + if filename and project.isOpen() and project.isProjectFile(filename): docstringStyle = project.getDocstringType().lower() - + if docstringStyle == "": docstringStyle = Preferences.getEditor("DocstringType") - + return docstringStyle - + def _generateDocstringList(self, functionInfo, docstringType): """ Protected method to generate type specific docstrings based on the extracted function information. - + @param functionInfo reference to the function info object @type FunctionInfo @param docstringType kind of docstring to be generated @@ -147,15 +144,19 @@ """ if docstringType == "ericdoc": from .EricdocGenerator import generateEricDoc + return generateEricDoc(functionInfo) elif docstringType == "numpydoc": from .NumpydocGenerator import generateNumpyDoc + return generateNumpyDoc(functionInfo) elif docstringType == "googledoc": from .GoogledocGenerator import generateGoogleDoc + return generateGoogleDoc(functionInfo, self.editor) elif docstringType == "sphinxdoc": from .SphinxdocGenerator import generateSphinxDoc + return generateSphinxDoc(functionInfo) else: return [] @@ -164,10 +165,11 @@ class FunctionInfo: """ Class implementing an object to store function information. - + Methods to extract the relevant information need to be implemented in language specific subclasses. """ + def __init__(self): """ Constructor @@ -175,7 +177,7 @@ self.hasInfo = False self.funcionText = "" self.argumentsText = "" - + self.functionIndent = "" # indentation fo function definition self.argumentsList = [] @@ -203,14 +205,15 @@ class DocstringMenuForEnterOnly(QMenu): """ Class implementing a special menu reacting to the enter/return keys only. - + If a keyboard input is not the "enter key", the menu is closed and the input is inserted to the code editor. """ + def __init__(self, editor): """ Constructor - + @param editor reference to the editor @type Editor """ @@ -220,7 +223,7 @@ def keyPressEvent(self, evt): """ Protected method to handle key press events. - + @param evt reference to the key press event object @type QKeyEvent """