Wed, 19 Oct 2022 17:00:05 +0200
Changed the PydocstringGenerator to adhere to the formatting rule of the 'Black' tool.
7998 | 1 | # -*- coding: utf-8 -*- |
2 | ||
8881
54e42bc2437a
Updated copyright for 2022.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8312
diff
changeset
|
3 | # Copyright (c) 2021 - 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
7998 | 4 | # |
5 | ||
6 | """ | |
7 | Module implementing a docstring generator for Python. | |
8 | """ | |
9 | ||
10 | import re | |
11 | import collections | |
12 | ||
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
13 | from .BaseDocstringGenerator import BaseDocstringGenerator, FunctionInfo, getIndentStr |
7998 | 14 | |
15 | ||
16 | class PyDocstringGenerator(BaseDocstringGenerator): | |
17 | """ | |
18 | Class implementing a docstring generator for Python. | |
19 | """ | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
20 | |
7998 | 21 | def __init__(self, editor): |
22 | """ | |
23 | Constructor | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
24 | |
7998 | 25 | @param editor reference to the editor widget |
26 | @type Editor | |
27 | """ | |
8218
7c09585bd960
Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8205
diff
changeset
|
28 | super().__init__(editor) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
29 | |
7998 | 30 | self.__quote3 = '"""' |
31 | self.__quote3Alternate = "'''" | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
32 | |
7998 | 33 | def isFunctionStart(self, text): |
34 | """ | |
35 | Public method to test, if a text is the start of a function or method | |
36 | definition. | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
37 | |
7998 | 38 | @param text line of text to be tested |
39 | @type str | |
40 | @return flag indicating that the given text starts a function or | |
41 | method definition | |
42 | @rtype bool | |
43 | """ | |
44 | if isinstance(text, str): | |
45 | text = text.lstrip() | |
9237
03c714bd4ebf
Fixed an issue in the docstring generator searching for the start of a function/method definition.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
46 | if text.startswith(("def ", "async def ")): |
7998 | 47 | return True |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
48 | |
7998 | 49 | return False |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
50 | |
7998 | 51 | def hasFunctionDefinition(self, cursorPosition): |
52 | """ | |
53 | Public method to test, if the cursor is right below a function | |
54 | definition. | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
55 | |
7998 | 56 | @param cursorPosition current cursor position (line and column) |
57 | @type tuple of (int, int) | |
58 | @return flag indicating cursor is right below a function definition | |
59 | @rtype bool | |
60 | """ | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
61 | return self.__getFunctionDefinitionFromBelow(cursorPosition) is not None |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
62 | |
7998 | 63 | def isDocstringIntro(self, cursorPosition): |
64 | """ | |
65 | Public function to test, if the line up to the cursor position might be | |
66 | introducing a docstring. | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
67 | |
7998 | 68 | @param cursorPosition current cursor position (line and column) |
69 | @type tuple of (int, int) | |
70 | @return flag indicating a potential start of a docstring | |
71 | @rtype bool | |
72 | """ | |
73 | cline, cindex = cursorPosition | |
74 | lineToCursor = self.editor.text(cline)[:cindex] | |
75 | return self.__isTripleQuotesStart(lineToCursor) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
76 | |
7998 | 77 | def __isTripleQuotesStart(self, text): |
78 | """ | |
79 | Private method to test, if the given text is the start of a triple | |
80 | quoted string. | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
81 | |
7998 | 82 | @param text text to be inspected |
83 | @type str | |
84 | @return flag indicating a triple quote start | |
85 | @rtype bool | |
86 | """ | |
87 | docstringTriggers = ('"""', 'r"""', "'''", "r'''") | |
88 | if text.lstrip() in docstringTriggers: | |
89 | return True | |
90 | ||
91 | return False | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
92 | |
7998 | 93 | def insertDocstring(self, cursorPosition, fromStart=True): |
94 | """ | |
95 | Public method to insert a docstring for the function at the cursor | |
96 | position. | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
97 | |
7998 | 98 | @param cursorPosition position of the cursor (line and index) |
99 | @type tuple of (int, int) | |
100 | @param fromStart flag indicating that the editor text cursor is placed | |
101 | on the line starting the function definition | |
102 | @type bool | |
103 | """ | |
104 | if fromStart: | |
105 | self.__functionStartLine = cursorPosition[0] | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
106 | docstring, insertPos, newCursorLine = self.__generateDocstringFromStart() |
7998 | 107 | else: |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
108 | docstring, insertPos, newCursorLine = self.__generateDocstringFromBelow( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
109 | cursorPosition |
8000
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
110 | ) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
111 | |
7998 | 112 | if docstring: |
113 | self.editor.beginUndoAction() | |
114 | self.editor.insertAt(docstring, *insertPos) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
115 | |
8000
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
116 | if not fromStart: |
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
117 | # correct triple quote indentation if neccessary |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
118 | functionIndent = self.editor.indentation(self.__functionStartLine) |
8000
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
119 | quoteIndent = self.editor.indentation(insertPos[0]) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
120 | |
8000
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
121 | # step 1: unindent quote line until indentation is zero |
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
122 | while quoteIndent > 0: |
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
123 | self.editor.unindent(insertPos[0]) |
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
124 | quoteIndent = self.editor.indentation(insertPos[0]) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
125 | |
8000
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
126 | # step 2: indent quote line until indentation is one greater |
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
127 | # than function definition line |
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
128 | while quoteIndent <= functionIndent: |
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
129 | self.editor.indent(insertPos[0]) |
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
130 | quoteIndent = self.editor.indentation(insertPos[0]) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
131 | |
7998 | 132 | self.editor.endUndoAction() |
8000
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
133 | self.editor.setCursorPosition( |
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
134 | newCursorLine, len(self.editor.text(newCursorLine)) - 1 |
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
135 | ) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
136 | |
8000
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
137 | def insertDocstringFromShortcut(self, cursorPosition): |
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
138 | """ |
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
139 | Public method to insert a docstring for the function at the cursor |
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
140 | position initiated via a keyboard shortcut. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
141 | |
8000
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
142 | @param cursorPosition position of the cursor (line and index) |
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
143 | @type tuple of (int, int) |
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
144 | """ |
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
145 | result = self.__getFunctionDefinitionFromBelow(cursorPosition) |
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
146 | if result is not None: |
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
147 | # cursor is on the line after the function definition |
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
148 | cline = cursorPosition[0] - 1 |
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
149 | while not self.isFunctionStart(self.editor.text(cline)): |
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
150 | cline -= 1 |
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
151 | self.__functionStartLine = cline |
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
152 | elif self.isFunctionStart(self.editor.text(cursorPosition[0])): |
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
153 | # cursor is on the start line of the function definition |
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
154 | self.__functionStartLine = cursorPosition[0] |
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
155 | else: |
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
156 | # neither after the function definition nor at the start |
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
157 | # just do nothing |
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
158 | return |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
159 | |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
160 | docstring, insertPos, newCursorLine = self.__generateDocstringFromStart() |
8000
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
161 | if docstring: |
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
162 | self.editor.beginUndoAction() |
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
163 | self.editor.insertAt(docstring, *insertPos) |
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
164 | self.editor.endUndoAction() |
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
165 | self.editor.setCursorPosition( |
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
166 | newCursorLine, len(self.editor.text(newCursorLine)) - 1 |
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
167 | ) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
168 | |
7998 | 169 | def __getIndentationInsertString(self, text): |
170 | """ | |
171 | Private method to create the indentation string for the docstring. | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
172 | |
7998 | 173 | @param text text to based the indentation on |
174 | @type str | |
175 | @return indentation string for docstring | |
176 | @rtype str | |
177 | """ | |
178 | indent = getIndentStr(text) | |
179 | indentWidth = self.editor.indentationWidth() | |
180 | if indentWidth == 0: | |
181 | indentWidth = self.editor.tabWidth() | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
182 | |
7998 | 183 | return indent + indentWidth * " " |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
184 | |
7998 | 185 | ####################################################################### |
186 | ## Methods to generate the docstring when the text cursor is on the | |
187 | ## line starting the function definition. | |
188 | ####################################################################### | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
189 | |
7998 | 190 | def __generateDocstringFromStart(self): |
191 | """ | |
192 | Private method to generate a docstring based on the cursor being | |
193 | placed on the first line of the definition. | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
194 | |
7998 | 195 | @return tuple containing the docstring and a tuple containing the |
196 | insertion line and index | |
197 | @rtype tuple of (str, tuple(int, int)) | |
198 | """ | |
199 | result = self.__getFunctionDefinitionFromStart() | |
200 | if result: | |
201 | functionDefinition, functionDefinitionLength = result | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
202 | |
7998 | 203 | insertLine = self.__functionStartLine + functionDefinitionLength |
204 | indentation = self.__getIndentationInsertString(functionDefinition) | |
205 | sep = self.editor.getLineSeparator() | |
206 | bodyStart = insertLine | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
207 | |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
208 | docstringList = self.__generateDocstring('"', functionDefinition, bodyStart) |
7998 | 209 | if docstringList: |
210 | if self.getDocstringType() == "ericdoc": | |
211 | docstringList.insert(0, self.__quote3) | |
8000
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
212 | newCursorLine = insertLine + 1 |
7998 | 213 | else: |
214 | docstringList[0] = self.__quote3 + docstringList[0] | |
8000
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
215 | newCursorLine = insertLine |
7998 | 216 | docstringList.append(self.__quote3) |
9422
cf2ea9c6316a
Changed the PydocstringGenerator to adhere to the formatting rule of the 'Black' tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9237
diff
changeset
|
217 | for index, line in enumerate(docstringList): |
cf2ea9c6316a
Changed the PydocstringGenerator to adhere to the formatting rule of the 'Black' tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9237
diff
changeset
|
218 | docstringList[index] = ( |
cf2ea9c6316a
Changed the PydocstringGenerator to adhere to the formatting rule of the 'Black' tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9237
diff
changeset
|
219 | indentation + line |
cf2ea9c6316a
Changed the PydocstringGenerator to adhere to the formatting rule of the 'Black' tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9237
diff
changeset
|
220 | if bool(line.strip()) |
cf2ea9c6316a
Changed the PydocstringGenerator to adhere to the formatting rule of the 'Black' tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9237
diff
changeset
|
221 | else "" |
cf2ea9c6316a
Changed the PydocstringGenerator to adhere to the formatting rule of the 'Black' tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9237
diff
changeset
|
222 | ) |
cf2ea9c6316a
Changed the PydocstringGenerator to adhere to the formatting rule of the 'Black' tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9237
diff
changeset
|
223 | return sep.join(docstringList) + sep, (insertLine, 0), newCursorLine |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
224 | |
8000
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
225 | return "", (0, 0), 0 |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
226 | |
7998 | 227 | def __getFunctionDefinitionFromStart(self): |
228 | """ | |
229 | Private method to extract the function definition based on the cursor | |
230 | being placed on the first line of the definition. | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
231 | |
7998 | 232 | @return text containing the function definition |
233 | @rtype str | |
234 | """ | |
235 | startLine = self.__functionStartLine | |
236 | endLine = startLine + min( | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
237 | self.editor.lines() - startLine, 20 # max. 20 lines of definition allowed |
7998 | 238 | ) |
239 | isFirstLine = True | |
240 | functionIndent = "" | |
241 | functionTextList = [] | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
242 | |
7998 | 243 | for lineNo in range(startLine, endLine): |
244 | text = self.editor.text(lineNo).rstrip() | |
245 | if isFirstLine: | |
246 | if not self.isFunctionStart(text): | |
247 | return None | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
248 | |
7998 | 249 | functionIndent = getIndentStr(text) |
250 | isFirstLine = False | |
251 | else: | |
252 | currentIndent = getIndentStr(text) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
253 | if currentIndent <= functionIndent or self.isFunctionStart(text): |
7998 | 254 | # no function body exists |
255 | return None | |
256 | if text.strip() == "": | |
257 | # empty line, illegal/incomplete function definition | |
258 | return None | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
259 | |
7998 | 260 | if text.endswith("\\"): |
261 | text = text[:-1] | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
262 | |
7998 | 263 | functionTextList.append(text) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
264 | |
7998 | 265 | if text.endswith(":"): |
266 | # end of function definition reached | |
267 | functionDefinitionLength = len(functionTextList) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
268 | |
7998 | 269 | # check, if function is decorated with a supported one |
270 | if startLine > 0: | |
271 | decoratorLine = self.editor.text(startLine - 1) | |
272 | if ( | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
273 | "@classmethod" in decoratorLine |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
274 | or "@staticmethod" in decoratorLine |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
275 | or "pyqtSlot" in decoratorLine |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
276 | or "Slot" in decoratorLine # PyQt slot # PySide slot |
7998 | 277 | ): |
278 | functionTextList.insert(0, decoratorLine) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
279 | |
7998 | 280 | return "".join(functionTextList), functionDefinitionLength |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
281 | |
7998 | 282 | return None |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
283 | |
7998 | 284 | ####################################################################### |
285 | ## Methods to generate the docstring when the text cursor is on the | |
286 | ## line after the function definition (e.g. after a triple quote). | |
287 | ####################################################################### | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
288 | |
7998 | 289 | def __generateDocstringFromBelow(self, cursorPosition): |
290 | """ | |
9422
cf2ea9c6316a
Changed the PydocstringGenerator to adhere to the formatting rule of the 'Black' tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9237
diff
changeset
|
291 | Private method to generate a docstring when the given position is on |
7998 | 292 | the line below the end of the definition. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
293 | |
7998 | 294 | @param cursorPosition position of the cursor (line and index) |
295 | @type tuple of (int, int) | |
296 | @return tuple containing the docstring and a tuple containing the | |
297 | insertion line and index | |
298 | @rtype tuple of (str, tuple(int, int)) | |
299 | """ | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
300 | functionDefinition = self.__getFunctionDefinitionFromBelow(cursorPosition) |
7998 | 301 | if functionDefinition: |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
302 | lineTextToCursor = self.editor.text(cursorPosition[0])[: cursorPosition[1]] |
7998 | 303 | insertLine = cursorPosition[0] |
304 | indentation = self.__getIndentationInsertString(functionDefinition) | |
305 | sep = self.editor.getLineSeparator() | |
306 | bodyStart = insertLine | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
307 | |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
308 | docstringList = self.__generateDocstring('"', functionDefinition, bodyStart) |
7998 | 309 | if docstringList: |
310 | if self.__isTripleQuotesStart(lineTextToCursor): | |
311 | if self.getDocstringType() == "ericdoc": | |
312 | docstringList.insert(0, "") | |
8000
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
313 | newCursorLine = cursorPosition[0] + 1 |
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
314 | else: |
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
315 | newCursorLine = cursorPosition[0] |
7998 | 316 | docstringList.append("") |
317 | else: | |
318 | if self.getDocstringType() == "ericdoc": | |
319 | docstringList.insert(0, self.__quote3) | |
8000
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
320 | newCursorLine = cursorPosition[0] + 1 |
7998 | 321 | else: |
322 | docstringList[0] = self.__quote3 + docstringList[0] | |
8000
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
323 | newCursorLine = cursorPosition[0] |
7998 | 324 | docstringList.append(self.__quote3) |
9422
cf2ea9c6316a
Changed the PydocstringGenerator to adhere to the formatting rule of the 'Black' tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9237
diff
changeset
|
325 | for index, line in enumerate(docstringList): |
cf2ea9c6316a
Changed the PydocstringGenerator to adhere to the formatting rule of the 'Black' tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9237
diff
changeset
|
326 | docstringList[index] = ( |
cf2ea9c6316a
Changed the PydocstringGenerator to adhere to the formatting rule of the 'Black' tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9237
diff
changeset
|
327 | indentation + line |
cf2ea9c6316a
Changed the PydocstringGenerator to adhere to the formatting rule of the 'Black' tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9237
diff
changeset
|
328 | if bool(line.strip()) |
cf2ea9c6316a
Changed the PydocstringGenerator to adhere to the formatting rule of the 'Black' tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9237
diff
changeset
|
329 | else "" |
cf2ea9c6316a
Changed the PydocstringGenerator to adhere to the formatting rule of the 'Black' tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9237
diff
changeset
|
330 | ) |
cf2ea9c6316a
Changed the PydocstringGenerator to adhere to the formatting rule of the 'Black' tool.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9237
diff
changeset
|
331 | docstring = sep.join(docstringList) + indentation |
8000
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
332 | return docstring, cursorPosition, newCursorLine |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
333 | |
8000
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
334 | return "", (0, 0), 0 |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
335 | |
7998 | 336 | def __getFunctionDefinitionFromBelow(self, cursorPosition): |
337 | """ | |
338 | Private method to extract the function definition based on the cursor | |
339 | being placed on the first line after the definition. | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
340 | |
7998 | 341 | @param cursorPosition current cursor position (line and column) |
342 | @type tuple of (int, int) | |
343 | @return text containing the function definition | |
344 | @rtype str | |
345 | """ | |
346 | startLine = cursorPosition[0] - 1 | |
347 | endLine = startLine - min(startLine, 20) | |
348 | # max. 20 lines of definition allowed | |
349 | isFirstLine = True | |
350 | functionTextList = [] | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
351 | |
7998 | 352 | for lineNo in range(startLine, endLine, -1): |
353 | text = self.editor.text(lineNo).rstrip() | |
354 | if isFirstLine: | |
355 | if not text.endswith(":"): | |
356 | return None | |
357 | isFirstLine = False | |
358 | elif text.endswith(":") or text == "": | |
359 | return None | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
360 | |
7998 | 361 | if text.endswith("\\"): |
362 | text = text[:-1] | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
363 | |
7998 | 364 | functionTextList.insert(0, text) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
365 | |
7998 | 366 | if self.isFunctionStart(text): |
367 | # start of function definition reached | |
8000
47b15df088e4
Editor: extended the docstring functionality to be invocable via a keyboard shortcut (Ctrl+Alt+D).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
7998
diff
changeset
|
368 | self.__functionStartLine = lineNo |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
369 | |
7998 | 370 | # check, if function is decorated with a supported one |
371 | if lineNo > 0: | |
372 | decoratorLine = self.editor.text(lineNo - 1) | |
373 | if ( | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
374 | "@classmethod" in decoratorLine |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
375 | or "@staticmethod" in decoratorLine |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
376 | or "pyqtSlot" in decoratorLine |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
377 | or "Slot" in decoratorLine # PyQt slot # PySide slot |
7998 | 378 | ): |
379 | functionTextList.insert(0, decoratorLine) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
380 | |
7998 | 381 | return "".join(functionTextList) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
382 | |
7998 | 383 | return None |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
384 | |
7998 | 385 | ####################################################################### |
386 | ## Methods to generate the docstring contents. | |
387 | ####################################################################### | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
388 | |
7998 | 389 | def __getFunctionBody(self, functionIndent, startLine): |
390 | """ | |
391 | Private method to get the function body. | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
392 | |
7998 | 393 | @param functionIndent indentation string of the function definition |
394 | @type str | |
395 | @param startLine starting line for the extraction process | |
396 | @type int | |
397 | @return text containing the function body | |
398 | @rtype str | |
399 | """ | |
400 | bodyList = [] | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
401 | |
7998 | 402 | for line in range(startLine, self.editor.lines()): |
403 | text = self.editor.text(line) | |
404 | textIndent = getIndentStr(text) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
405 | |
7998 | 406 | if text.strip() == "": |
407 | pass | |
408 | elif len(textIndent) <= len(functionIndent): | |
409 | break | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
410 | |
7998 | 411 | bodyList.append(text) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
412 | |
7998 | 413 | return "".join(bodyList) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
414 | |
7998 | 415 | def __generateDocstring(self, quote, functionDef, bodyStartLine): |
416 | """ | |
417 | Private method to generate the list of docstring lines. | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
418 | |
7998 | 419 | @param quote quote string |
420 | @type str | |
421 | @param functionDef text containing the function definition | |
422 | @type str | |
423 | @param bodyStartLine starting line of the function body | |
424 | @type int | |
425 | @return list of docstring lines | |
426 | @rtype list of str | |
427 | """ | |
428 | quote3 = 3 * quote | |
429 | if quote == '"': | |
430 | quote3replace = 3 * "'" | |
431 | elif quote == "'": | |
432 | quote3replace = 3 * '"' | |
433 | functionInfo = PyFunctionInfo() | |
434 | functionInfo.parseDefinition(functionDef, quote3, quote3replace) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
435 | |
7998 | 436 | if functionInfo.hasInfo: |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
437 | functionBody = self.__getFunctionBody( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
438 | functionInfo.functionIndent, bodyStartLine |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
439 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
440 | |
7998 | 441 | if functionBody: |
442 | functionInfo.parseBody(functionBody) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
443 | |
7998 | 444 | docstringType = self.getDocstringType() |
445 | return self._generateDocstringList(functionInfo, docstringType) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
446 | |
7998 | 447 | return [] |
448 | ||
449 | ||
450 | class PyFunctionInfo(FunctionInfo): | |
451 | """ | |
452 | Class implementing an object to extract and store function information. | |
453 | """ | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
454 | |
7998 | 455 | def __init__(self): |
456 | """ | |
457 | Constructor | |
458 | """ | |
8218
7c09585bd960
Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8205
diff
changeset
|
459 | super().__init__() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
460 | |
7998 | 461 | def __isCharInPairs(self, posChar, pairs): |
462 | """ | |
463 | Private method to test, if the given character position is between | |
464 | pairs of brackets or quotes. | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
465 | |
7998 | 466 | @param posChar character position to be tested |
467 | @type int | |
468 | @param pairs list containing pairs of positions | |
469 | @type list of tuple of (int, int) | |
470 | @return flag indicating the position is in between | |
471 | @rtype bool | |
472 | """ | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
473 | return any(posLeft < posChar < posRight for (posLeft, posRight) in pairs) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
474 | |
7998 | 475 | def __findQuotePosition(self, text): |
476 | """ | |
477 | Private method to find the start and end position of pairs of quotes. | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
478 | |
7998 | 479 | @param text text to be parsed |
480 | @type str | |
481 | @return list of tuple with start and end position of pairs of quotes | |
482 | @rtype list of tuple of (int, int) | |
483 | @exception IndexError raised when a matching close quote is missing | |
484 | """ | |
485 | pos = [] | |
486 | foundLeftQuote = False | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
487 | |
7998 | 488 | for index, character in enumerate(text): |
489 | if foundLeftQuote is False: | |
8205
4a0f1f896341
Applied some code simplifications suggested by the new Simplify checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8000
diff
changeset
|
490 | if character in ("'", '"'): |
7998 | 491 | foundLeftQuote = True |
492 | quote = character | |
493 | leftPos = index | |
494 | else: | |
495 | if character == quote and text[index - 1] != "\\": | |
496 | pos.append((leftPos, index)) | |
497 | foundLeftQuote = False | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
498 | |
7998 | 499 | if foundLeftQuote: |
500 | raise IndexError("No matching close quote at: {0}".format(leftPos)) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
501 | |
7998 | 502 | return pos |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
503 | |
7998 | 504 | def __findBracketPosition(self, text, bracketLeft, bracketRight, posQuote): |
505 | """ | |
506 | Private method to find the start and end position of pairs of brackets. | |
507 | ||
508 | https://stackoverflow.com/questions/29991917/ | |
509 | indices-of-matching-parentheses-in-python | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
510 | |
7998 | 511 | @param text text to be parsed |
512 | @type str | |
513 | @param bracketLeft character of the left bracket | |
514 | @type str | |
515 | @param bracketRight character of the right bracket | |
516 | @type str | |
517 | @param posQuote list of tuple with start and end position of pairs | |
518 | of quotes | |
519 | @type list of tuple of (int, int) | |
520 | @return list of tuple with start and end position of pairs of brackets | |
521 | @rtype list of tuple of (int, int) | |
522 | @exception IndexError raised when a closing or opening bracket is | |
523 | missing | |
524 | """ | |
525 | pos = [] | |
526 | pstack = [] | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
527 | |
7998 | 528 | for index, character in enumerate(text): |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
529 | if character == bracketLeft and not self.__isCharInPairs(index, posQuote): |
7998 | 530 | pstack.append(index) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
531 | elif character == bracketRight and not self.__isCharInPairs( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
532 | index, posQuote |
7998 | 533 | ): |
534 | if len(pstack) == 0: | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
535 | raise IndexError("No matching closing parens at: {0}".format(index)) |
7998 | 536 | pos.append((pstack.pop(), index)) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
537 | |
7998 | 538 | if len(pstack) > 0: |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
539 | raise IndexError("No matching opening parens at: {0}".format(pstack.pop())) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
540 | |
7998 | 541 | return pos |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
542 | |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
543 | def __splitArgumentToNameTypeValue(self, argumentsList, quote, quoteReplace): |
7998 | 544 | """ |
545 | Private method to split some argument text to name, type and value. | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
546 | |
7998 | 547 | @param argumentsList list of function argument definitions |
548 | @type list of str | |
549 | @param quote quote string to be replaced | |
550 | @type str | |
551 | @param quoteReplace quote string to replace the original | |
552 | @type str | |
553 | """ | |
554 | for arg in argumentsList: | |
555 | hasType = False | |
556 | hasValue = False | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
557 | |
7998 | 558 | colonPosition = arg.find(":") |
559 | equalPosition = arg.find("=") | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
560 | |
7998 | 561 | if equalPosition > -1: |
562 | hasValue = True | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
563 | |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
564 | if colonPosition > -1 and (not hasValue or equalPosition > colonPosition): |
8229
6fa22aa4fc4a
Applied some more code simplifications suggested by the new Simplify checker (Y102: use single if) (batch 2+).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8228
diff
changeset
|
565 | # exception for def foo(arg1=":") |
6fa22aa4fc4a
Applied some more code simplifications suggested by the new Simplify checker (Y102: use single if) (batch 2+).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8228
diff
changeset
|
566 | hasType = True |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
567 | |
7998 | 568 | if hasValue and hasType: |
569 | argName = arg[0:colonPosition].strip() | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
570 | argType = arg[colonPosition + 1 : equalPosition].strip() |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
571 | argValue = arg[equalPosition + 1 :].strip() |
7998 | 572 | elif not hasValue and hasType: |
573 | argName = arg[0:colonPosition].strip() | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
574 | argType = arg[colonPosition + 1 :].strip() |
7998 | 575 | argValue = None |
576 | elif hasValue and not hasType: | |
577 | argName = arg[0:equalPosition].strip() | |
578 | argType = None | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
579 | argValue = arg[equalPosition + 1 :].strip() |
7998 | 580 | else: |
581 | argName = arg.strip() | |
582 | argType = None | |
583 | argValue = None | |
584 | if argValue and quote: | |
585 | # sanitize argValue with respect to quotes | |
586 | argValue = argValue.replace(quote, quoteReplace) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
587 | |
7998 | 588 | self.argumentsList.append((argName, argType, argValue)) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
589 | |
7998 | 590 | def __splitArgumentsTextToList(self, argumentsText): |
591 | """ | |
592 | Private method to split the given arguments text into a list of | |
593 | arguments. | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
594 | |
7998 | 595 | This function uses a comma to separate arguments and ignores a comma in |
596 | brackets and quotes. | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
597 | |
7998 | 598 | @param argumentsText text containing the list of arguments |
599 | @type str | |
600 | @return list of individual argument texts | |
601 | @rtype list of str | |
602 | """ | |
603 | argumentsList = [] | |
604 | indexFindStart = 0 | |
605 | indexArgStart = 0 | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
606 | |
7998 | 607 | try: |
608 | posQuote = self.__findQuotePosition(argumentsText) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
609 | posRound = self.__findBracketPosition(argumentsText, "(", ")", posQuote) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
610 | posCurly = self.__findBracketPosition(argumentsText, "{", "}", posQuote) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
611 | posSquare = self.__findBracketPosition(argumentsText, "[", "]", posQuote) |
7998 | 612 | except IndexError: |
613 | return None | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
614 | |
7998 | 615 | while True: |
616 | posComma = argumentsText.find(",", indexFindStart) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
617 | |
7998 | 618 | if posComma == -1: |
619 | break | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
620 | |
7998 | 621 | indexFindStart = posComma + 1 |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
622 | |
7998 | 623 | if ( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
624 | self.__isCharInPairs(posComma, posRound) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
625 | or self.__isCharInPairs(posComma, posCurly) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
626 | or self.__isCharInPairs(posComma, posSquare) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
627 | or self.__isCharInPairs(posComma, posQuote) |
7998 | 628 | ): |
629 | continue | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
630 | |
7998 | 631 | argumentsList.append(argumentsText[indexArgStart:posComma]) |
632 | indexArgStart = posComma + 1 | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
633 | |
7998 | 634 | if indexArgStart < len(argumentsText): |
635 | argumentsList.append(argumentsText[indexArgStart:]) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
636 | |
7998 | 637 | return argumentsList |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
638 | |
7998 | 639 | def parseDefinition(self, text, quote, quoteReplace): |
640 | """ | |
641 | Public method to parse the function definition text. | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
642 | |
7998 | 643 | @param text text containing the function definition |
644 | @type str | |
645 | @param quote quote string to be replaced | |
646 | @type str | |
647 | @param quoteReplace quote string to replace the original | |
648 | @type str | |
649 | """ | |
650 | self.functionIndent = getIndentStr(text) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
651 | |
7998 | 652 | textList = text.splitlines() |
653 | if textList[0].lstrip().startswith("@"): | |
654 | # first line of function definition is a decorator | |
655 | decorator = textList.pop(0).strip() | |
656 | if decorator == "@staticmethod": | |
657 | self.functionType = "staticmethod" | |
658 | elif decorator == "@classmethod": | |
659 | self.functionType = "classmethod" | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
660 | elif re.match(r"@(PyQt[456]\.)?(QtCore\.)?pyqtSlot", decorator) or re.match( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
661 | r"@(PySide[26]\.)?(QtCore\.)?Slot", decorator |
8228
772103b14c18
Applied some more code simplifications suggested by the new Simplify checker (Y114: use logical or for multiple if).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8222
diff
changeset
|
662 | ): |
7998 | 663 | self.functionType = "qtslot" |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
664 | |
7998 | 665 | text = "".join(textList).strip() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
666 | |
7998 | 667 | if text.startswith("async def "): |
668 | self.isAsync = True | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
669 | |
7998 | 670 | returnType = re.search(r"->[ ]*([a-zA-Z0-9_,()\[\] ]*):$", text) |
671 | if returnType: | |
672 | self.returnTypeAnnotated = returnType.group(1) | |
673 | textEnd = text.rfind(returnType.group(0)) | |
674 | else: | |
675 | self.returnTypeAnnotated = None | |
676 | textEnd = len(text) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
677 | |
7998 | 678 | positionArgumentsStart = text.find("(") + 1 |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
679 | positionArgumentsEnd = text.rfind(")", positionArgumentsStart, textEnd) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
680 | |
7998 | 681 | self.argumentsText = text[positionArgumentsStart:positionArgumentsEnd] |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
682 | |
7998 | 683 | argumentsList = self.__splitArgumentsTextToList(self.argumentsText) |
684 | if argumentsList is not None: | |
685 | self.hasInfo = True | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
686 | self.__splitArgumentToNameTypeValue(argumentsList, quote, quoteReplace) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
687 | |
7998 | 688 | functionName = ( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
689 | text[: positionArgumentsStart - 1] |
7998 | 690 | .replace("async def ", "") |
691 | .replace("def ", "") | |
692 | ) | |
693 | if functionName == "__init__": | |
694 | self.functionType = "constructor" | |
695 | elif functionName.startswith("__"): | |
696 | if functionName.endswith("__"): | |
697 | self.visibility = "special" | |
698 | else: | |
699 | self.visibility = "private" | |
700 | elif functionName.startswith("_"): | |
701 | self.visibility = "protected" | |
702 | else: | |
703 | self.visibility = "public" | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
704 | |
7998 | 705 | def parseBody(self, text): |
706 | """ | |
707 | Public method to parse the function body text. | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
708 | |
7998 | 709 | @param text function body text |
710 | @type str | |
711 | """ | |
712 | raiseRe = re.findall(r"[ \t]raise ([a-zA-Z0-9_]*)", text) | |
713 | if len(raiseRe) > 0: | |
714 | self.raiseList = [x.strip() for x in raiseRe] | |
715 | # remove duplicates from list while keeping it in the order | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
716 | self.raiseList = list(collections.OrderedDict.fromkeys(self.raiseList)) |
7998 | 717 | |
718 | yieldRe = re.search(r"[ \t]yield ", text) | |
719 | if yieldRe: | |
720 | self.hasYield = True | |
721 | ||
722 | # get return value | |
723 | returnPattern = r"return |yield " | |
724 | lineList = text.splitlines() | |
725 | returnFound = False | |
726 | returnTmpLine = "" | |
727 | ||
728 | for line in lineList: | |
729 | line = line.strip() | |
730 | ||
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
731 | if returnFound is False and re.match(returnPattern, line): |
8222
5994b80b8760
Applied some more code simplifications suggested by the new Simplify checker (Y102: use single if) (batch 1).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8221
diff
changeset
|
732 | returnFound = True |
7998 | 733 | |
734 | if returnFound: | |
735 | returnTmpLine += line | |
736 | # check the integrity of line | |
737 | try: | |
738 | quotePos = self.__findQuotePosition(returnTmpLine) | |
739 | ||
740 | if returnTmpLine.endswith("\\"): | |
741 | returnTmpLine = returnTmpLine[:-1] | |
742 | continue | |
743 | ||
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
744 | self.__findBracketPosition(returnTmpLine, "(", ")", quotePos) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
745 | self.__findBracketPosition(returnTmpLine, "{", "}", quotePos) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
746 | self.__findBracketPosition(returnTmpLine, "[", "]", quotePos) |
7998 | 747 | except IndexError: |
748 | continue | |
749 | ||
750 | returnValue = re.sub(returnPattern, "", returnTmpLine) | |
751 | self.returnValueInBody.append(returnValue) | |
752 | ||
753 | returnFound = False | |
754 | returnTmpLine = "" |