Mon, 07 Nov 2022 17:19:58 +0100
Corrected/acknowledged some bad import style and removed some obsolete code.
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 | ||
9473
3f23dbf37dbe
Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9453
diff
changeset
|
10 | import collections |
7998 | 11 | import re |
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] = ( |
9453
e5065dde905d
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9422
diff
changeset
|
219 | indentation + line if bool(line.strip()) else "" |
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
|
220 | ) |
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 | 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
|
222 | |
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
|
223 | return "", (0, 0), 0 |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
224 | |
7998 | 225 | def __getFunctionDefinitionFromStart(self): |
226 | """ | |
227 | Private method to extract the function definition based on the cursor | |
228 | 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
|
229 | |
7998 | 230 | @return text containing the function definition |
231 | @rtype str | |
232 | """ | |
233 | startLine = self.__functionStartLine | |
234 | endLine = startLine + min( | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
235 | self.editor.lines() - startLine, 20 # max. 20 lines of definition allowed |
7998 | 236 | ) |
237 | isFirstLine = True | |
238 | functionIndent = "" | |
239 | functionTextList = [] | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
240 | |
7998 | 241 | for lineNo in range(startLine, endLine): |
242 | text = self.editor.text(lineNo).rstrip() | |
243 | if isFirstLine: | |
244 | if not self.isFunctionStart(text): | |
245 | return None | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
246 | |
7998 | 247 | functionIndent = getIndentStr(text) |
248 | isFirstLine = False | |
249 | else: | |
250 | currentIndent = getIndentStr(text) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
251 | if currentIndent <= functionIndent or self.isFunctionStart(text): |
7998 | 252 | # no function body exists |
253 | return None | |
254 | if text.strip() == "": | |
255 | # empty line, illegal/incomplete function definition | |
256 | return None | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
257 | |
7998 | 258 | if text.endswith("\\"): |
259 | text = text[:-1] | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
260 | |
7998 | 261 | functionTextList.append(text) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
262 | |
7998 | 263 | if text.endswith(":"): |
264 | # end of function definition reached | |
265 | functionDefinitionLength = len(functionTextList) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
266 | |
7998 | 267 | # check, if function is decorated with a supported one |
268 | if startLine > 0: | |
269 | decoratorLine = self.editor.text(startLine - 1) | |
270 | if ( | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
271 | "@classmethod" in decoratorLine |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
272 | or "@staticmethod" in decoratorLine |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
273 | or "pyqtSlot" in decoratorLine |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
274 | or "Slot" in decoratorLine # PyQt slot # PySide slot |
7998 | 275 | ): |
276 | functionTextList.insert(0, decoratorLine) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
277 | |
7998 | 278 | return "".join(functionTextList), functionDefinitionLength |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
279 | |
7998 | 280 | return None |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
281 | |
7998 | 282 | ####################################################################### |
283 | ## Methods to generate the docstring when the text cursor is on the | |
284 | ## line after the function definition (e.g. after a triple quote). | |
285 | ####################################################################### | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
286 | |
7998 | 287 | def __generateDocstringFromBelow(self, cursorPosition): |
288 | """ | |
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
|
289 | Private method to generate a docstring when the given position is on |
7998 | 290 | 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
|
291 | |
7998 | 292 | @param cursorPosition position of the cursor (line and index) |
293 | @type tuple of (int, int) | |
294 | @return tuple containing the docstring and a tuple containing the | |
295 | insertion line and index | |
296 | @rtype tuple of (str, tuple(int, int)) | |
297 | """ | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
298 | functionDefinition = self.__getFunctionDefinitionFromBelow(cursorPosition) |
7998 | 299 | if functionDefinition: |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
300 | lineTextToCursor = self.editor.text(cursorPosition[0])[: cursorPosition[1]] |
7998 | 301 | insertLine = cursorPosition[0] |
302 | indentation = self.__getIndentationInsertString(functionDefinition) | |
303 | sep = self.editor.getLineSeparator() | |
304 | bodyStart = insertLine | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
305 | |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
306 | docstringList = self.__generateDocstring('"', functionDefinition, bodyStart) |
7998 | 307 | if docstringList: |
308 | if self.__isTripleQuotesStart(lineTextToCursor): | |
309 | if self.getDocstringType() == "ericdoc": | |
310 | 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
|
311 | 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
|
312 | 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
|
313 | newCursorLine = cursorPosition[0] |
7998 | 314 | docstringList.append("") |
315 | else: | |
316 | if self.getDocstringType() == "ericdoc": | |
317 | 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
|
318 | newCursorLine = cursorPosition[0] + 1 |
7998 | 319 | else: |
320 | 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
|
321 | newCursorLine = cursorPosition[0] |
7998 | 322 | 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
|
323 | 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
|
324 | docstringList[index] = ( |
9453
e5065dde905d
Code Formatting
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9422
diff
changeset
|
325 | indentation + line if bool(line.strip()) else "" |
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
|
326 | ) |
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 | 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
|
328 | return docstring, cursorPosition, newCursorLine |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
329 | |
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
|
330 | return "", (0, 0), 0 |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
331 | |
7998 | 332 | def __getFunctionDefinitionFromBelow(self, cursorPosition): |
333 | """ | |
334 | Private method to extract the function definition based on the cursor | |
335 | 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
|
336 | |
7998 | 337 | @param cursorPosition current cursor position (line and column) |
338 | @type tuple of (int, int) | |
339 | @return text containing the function definition | |
340 | @rtype str | |
341 | """ | |
342 | startLine = cursorPosition[0] - 1 | |
343 | endLine = startLine - min(startLine, 20) | |
344 | # max. 20 lines of definition allowed | |
345 | isFirstLine = True | |
346 | functionTextList = [] | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
347 | |
7998 | 348 | for lineNo in range(startLine, endLine, -1): |
349 | text = self.editor.text(lineNo).rstrip() | |
350 | if isFirstLine: | |
351 | if not text.endswith(":"): | |
352 | return None | |
353 | isFirstLine = False | |
354 | elif text.endswith(":") or text == "": | |
355 | return None | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
356 | |
7998 | 357 | if text.endswith("\\"): |
358 | text = text[:-1] | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
359 | |
7998 | 360 | functionTextList.insert(0, text) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
361 | |
7998 | 362 | if self.isFunctionStart(text): |
363 | # 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
|
364 | self.__functionStartLine = lineNo |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
365 | |
7998 | 366 | # check, if function is decorated with a supported one |
367 | if lineNo > 0: | |
368 | decoratorLine = self.editor.text(lineNo - 1) | |
369 | if ( | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
370 | "@classmethod" in decoratorLine |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
371 | or "@staticmethod" in decoratorLine |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
372 | or "pyqtSlot" in decoratorLine |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
373 | or "Slot" in decoratorLine # PyQt slot # PySide slot |
7998 | 374 | ): |
375 | functionTextList.insert(0, decoratorLine) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
376 | |
7998 | 377 | return "".join(functionTextList) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
378 | |
7998 | 379 | return None |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
380 | |
7998 | 381 | ####################################################################### |
382 | ## Methods to generate the docstring contents. | |
383 | ####################################################################### | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
384 | |
7998 | 385 | def __getFunctionBody(self, functionIndent, startLine): |
386 | """ | |
387 | 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
|
388 | |
7998 | 389 | @param functionIndent indentation string of the function definition |
390 | @type str | |
391 | @param startLine starting line for the extraction process | |
392 | @type int | |
393 | @return text containing the function body | |
394 | @rtype str | |
395 | """ | |
396 | bodyList = [] | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
397 | |
7998 | 398 | for line in range(startLine, self.editor.lines()): |
399 | text = self.editor.text(line) | |
400 | textIndent = getIndentStr(text) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
401 | |
7998 | 402 | if text.strip() == "": |
403 | pass | |
404 | elif len(textIndent) <= len(functionIndent): | |
405 | break | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
406 | |
7998 | 407 | bodyList.append(text) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
408 | |
7998 | 409 | return "".join(bodyList) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
410 | |
7998 | 411 | def __generateDocstring(self, quote, functionDef, bodyStartLine): |
412 | """ | |
413 | 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
|
414 | |
7998 | 415 | @param quote quote string |
416 | @type str | |
417 | @param functionDef text containing the function definition | |
418 | @type str | |
419 | @param bodyStartLine starting line of the function body | |
420 | @type int | |
421 | @return list of docstring lines | |
422 | @rtype list of str | |
423 | """ | |
424 | quote3 = 3 * quote | |
425 | if quote == '"': | |
426 | quote3replace = 3 * "'" | |
427 | elif quote == "'": | |
428 | quote3replace = 3 * '"' | |
429 | functionInfo = PyFunctionInfo() | |
430 | 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
|
431 | |
7998 | 432 | if functionInfo.hasInfo: |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
433 | functionBody = self.__getFunctionBody( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
434 | functionInfo.functionIndent, bodyStartLine |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
435 | ) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
436 | |
7998 | 437 | if functionBody: |
438 | functionInfo.parseBody(functionBody) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
439 | |
7998 | 440 | docstringType = self.getDocstringType() |
441 | 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
|
442 | |
7998 | 443 | return [] |
444 | ||
445 | ||
446 | class PyFunctionInfo(FunctionInfo): | |
447 | """ | |
448 | Class implementing an object to extract and store function information. | |
449 | """ | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
450 | |
7998 | 451 | def __init__(self): |
452 | """ | |
453 | Constructor | |
454 | """ | |
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
|
455 | super().__init__() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
456 | |
7998 | 457 | def __isCharInPairs(self, posChar, pairs): |
458 | """ | |
459 | Private method to test, if the given character position is between | |
460 | 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
|
461 | |
7998 | 462 | @param posChar character position to be tested |
463 | @type int | |
464 | @param pairs list containing pairs of positions | |
465 | @type list of tuple of (int, int) | |
466 | @return flag indicating the position is in between | |
467 | @rtype bool | |
468 | """ | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
469 | 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
|
470 | |
7998 | 471 | def __findQuotePosition(self, text): |
472 | """ | |
473 | 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
|
474 | |
7998 | 475 | @param text text to be parsed |
476 | @type str | |
477 | @return list of tuple with start and end position of pairs of quotes | |
478 | @rtype list of tuple of (int, int) | |
479 | @exception IndexError raised when a matching close quote is missing | |
480 | """ | |
481 | pos = [] | |
482 | foundLeftQuote = False | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
483 | |
7998 | 484 | for index, character in enumerate(text): |
485 | 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
|
486 | if character in ("'", '"'): |
7998 | 487 | foundLeftQuote = True |
488 | quote = character | |
489 | leftPos = index | |
490 | else: | |
491 | if character == quote and text[index - 1] != "\\": | |
492 | pos.append((leftPos, index)) | |
493 | foundLeftQuote = False | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
494 | |
7998 | 495 | if foundLeftQuote: |
496 | 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
|
497 | |
7998 | 498 | return pos |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
499 | |
7998 | 500 | def __findBracketPosition(self, text, bracketLeft, bracketRight, posQuote): |
501 | """ | |
502 | Private method to find the start and end position of pairs of brackets. | |
503 | ||
504 | https://stackoverflow.com/questions/29991917/ | |
505 | 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
|
506 | |
7998 | 507 | @param text text to be parsed |
508 | @type str | |
509 | @param bracketLeft character of the left bracket | |
510 | @type str | |
511 | @param bracketRight character of the right bracket | |
512 | @type str | |
513 | @param posQuote list of tuple with start and end position of pairs | |
514 | of quotes | |
515 | @type list of tuple of (int, int) | |
516 | @return list of tuple with start and end position of pairs of brackets | |
517 | @rtype list of tuple of (int, int) | |
518 | @exception IndexError raised when a closing or opening bracket is | |
519 | missing | |
520 | """ | |
521 | pos = [] | |
522 | pstack = [] | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
523 | |
7998 | 524 | 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
|
525 | if character == bracketLeft and not self.__isCharInPairs(index, posQuote): |
7998 | 526 | pstack.append(index) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
527 | 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
|
528 | index, posQuote |
7998 | 529 | ): |
530 | if len(pstack) == 0: | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
531 | raise IndexError("No matching closing parens at: {0}".format(index)) |
7998 | 532 | 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
|
533 | |
7998 | 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 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
|
536 | |
7998 | 537 | return pos |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
538 | |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
539 | def __splitArgumentToNameTypeValue(self, argumentsList, quote, quoteReplace): |
7998 | 540 | """ |
541 | 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
|
542 | |
7998 | 543 | @param argumentsList list of function argument definitions |
544 | @type list of str | |
545 | @param quote quote string to be replaced | |
546 | @type str | |
547 | @param quoteReplace quote string to replace the original | |
548 | @type str | |
549 | """ | |
550 | for arg in argumentsList: | |
551 | hasType = False | |
552 | hasValue = False | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
553 | |
7998 | 554 | colonPosition = arg.find(":") |
555 | equalPosition = arg.find("=") | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
556 | |
7998 | 557 | if equalPosition > -1: |
558 | hasValue = True | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
559 | |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
560 | 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
|
561 | # 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
|
562 | hasType = True |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
563 | |
7998 | 564 | if hasValue and hasType: |
565 | 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
|
566 | 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
|
567 | argValue = arg[equalPosition + 1 :].strip() |
7998 | 568 | elif not 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 :].strip() |
7998 | 571 | argValue = None |
572 | elif hasValue and not hasType: | |
573 | argName = arg[0:equalPosition].strip() | |
574 | argType = None | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
575 | argValue = arg[equalPosition + 1 :].strip() |
7998 | 576 | else: |
577 | argName = arg.strip() | |
578 | argType = None | |
579 | argValue = None | |
580 | if argValue and quote: | |
581 | # sanitize argValue with respect to quotes | |
582 | 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
|
583 | |
7998 | 584 | 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
|
585 | |
7998 | 586 | def __splitArgumentsTextToList(self, argumentsText): |
587 | """ | |
588 | Private method to split the given arguments text into a list of | |
589 | arguments. | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
590 | |
7998 | 591 | This function uses a comma to separate arguments and ignores a comma in |
592 | brackets and quotes. | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
593 | |
7998 | 594 | @param argumentsText text containing the list of arguments |
595 | @type str | |
596 | @return list of individual argument texts | |
597 | @rtype list of str | |
598 | """ | |
599 | argumentsList = [] | |
600 | indexFindStart = 0 | |
601 | indexArgStart = 0 | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
602 | |
7998 | 603 | try: |
604 | posQuote = self.__findQuotePosition(argumentsText) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
605 | posRound = self.__findBracketPosition(argumentsText, "(", ")", posQuote) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
606 | posCurly = self.__findBracketPosition(argumentsText, "{", "}", posQuote) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
607 | posSquare = self.__findBracketPosition(argumentsText, "[", "]", posQuote) |
7998 | 608 | except IndexError: |
609 | return None | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
610 | |
7998 | 611 | while True: |
612 | posComma = argumentsText.find(",", indexFindStart) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
613 | |
7998 | 614 | if posComma == -1: |
615 | break | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
616 | |
7998 | 617 | indexFindStart = posComma + 1 |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
618 | |
7998 | 619 | if ( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
620 | self.__isCharInPairs(posComma, posRound) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
621 | or self.__isCharInPairs(posComma, posCurly) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
622 | or self.__isCharInPairs(posComma, posSquare) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
623 | or self.__isCharInPairs(posComma, posQuote) |
7998 | 624 | ): |
625 | continue | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
626 | |
7998 | 627 | argumentsList.append(argumentsText[indexArgStart:posComma]) |
628 | indexArgStart = posComma + 1 | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
629 | |
7998 | 630 | if indexArgStart < len(argumentsText): |
631 | argumentsList.append(argumentsText[indexArgStart:]) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
632 | |
7998 | 633 | return argumentsList |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
634 | |
7998 | 635 | def parseDefinition(self, text, quote, quoteReplace): |
636 | """ | |
637 | 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
|
638 | |
7998 | 639 | @param text text containing the function definition |
640 | @type str | |
641 | @param quote quote string to be replaced | |
642 | @type str | |
643 | @param quoteReplace quote string to replace the original | |
644 | @type str | |
645 | """ | |
646 | self.functionIndent = getIndentStr(text) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
647 | |
7998 | 648 | textList = text.splitlines() |
649 | if textList[0].lstrip().startswith("@"): | |
650 | # first line of function definition is a decorator | |
651 | decorator = textList.pop(0).strip() | |
652 | if decorator == "@staticmethod": | |
653 | self.functionType = "staticmethod" | |
654 | elif decorator == "@classmethod": | |
655 | self.functionType = "classmethod" | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
656 | 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
|
657 | 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
|
658 | ): |
7998 | 659 | self.functionType = "qtslot" |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
660 | |
7998 | 661 | text = "".join(textList).strip() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
662 | |
7998 | 663 | if text.startswith("async def "): |
664 | self.isAsync = True | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
665 | |
7998 | 666 | returnType = re.search(r"->[ ]*([a-zA-Z0-9_,()\[\] ]*):$", text) |
667 | if returnType: | |
668 | self.returnTypeAnnotated = returnType.group(1) | |
669 | textEnd = text.rfind(returnType.group(0)) | |
670 | else: | |
671 | self.returnTypeAnnotated = None | |
672 | textEnd = len(text) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
673 | |
7998 | 674 | positionArgumentsStart = text.find("(") + 1 |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
675 | positionArgumentsEnd = text.rfind(")", positionArgumentsStart, textEnd) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
676 | |
7998 | 677 | 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
|
678 | |
7998 | 679 | argumentsList = self.__splitArgumentsTextToList(self.argumentsText) |
680 | if argumentsList is not None: | |
681 | self.hasInfo = True | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
682 | self.__splitArgumentToNameTypeValue(argumentsList, quote, quoteReplace) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
683 | |
7998 | 684 | functionName = ( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
685 | text[: positionArgumentsStart - 1] |
7998 | 686 | .replace("async def ", "") |
687 | .replace("def ", "") | |
688 | ) | |
689 | if functionName == "__init__": | |
690 | self.functionType = "constructor" | |
691 | elif functionName.startswith("__"): | |
692 | if functionName.endswith("__"): | |
693 | self.visibility = "special" | |
694 | else: | |
695 | self.visibility = "private" | |
696 | elif functionName.startswith("_"): | |
697 | self.visibility = "protected" | |
698 | else: | |
699 | self.visibility = "public" | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
700 | |
7998 | 701 | def parseBody(self, text): |
702 | """ | |
703 | 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
|
704 | |
7998 | 705 | @param text function body text |
706 | @type str | |
707 | """ | |
708 | raiseRe = re.findall(r"[ \t]raise ([a-zA-Z0-9_]*)", text) | |
709 | if len(raiseRe) > 0: | |
710 | self.raiseList = [x.strip() for x in raiseRe] | |
711 | # 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
|
712 | self.raiseList = list(collections.OrderedDict.fromkeys(self.raiseList)) |
7998 | 713 | |
714 | yieldRe = re.search(r"[ \t]yield ", text) | |
715 | if yieldRe: | |
716 | self.hasYield = True | |
717 | ||
718 | # get return value | |
719 | returnPattern = r"return |yield " | |
720 | lineList = text.splitlines() | |
721 | returnFound = False | |
722 | returnTmpLine = "" | |
723 | ||
724 | for line in lineList: | |
725 | line = line.strip() | |
726 | ||
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
727 | 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
|
728 | returnFound = True |
7998 | 729 | |
730 | if returnFound: | |
731 | returnTmpLine += line | |
732 | # check the integrity of line | |
733 | try: | |
734 | quotePos = self.__findQuotePosition(returnTmpLine) | |
735 | ||
736 | if returnTmpLine.endswith("\\"): | |
737 | returnTmpLine = returnTmpLine[:-1] | |
738 | continue | |
739 | ||
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
740 | self.__findBracketPosition(returnTmpLine, "(", ")", quotePos) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
741 | self.__findBracketPosition(returnTmpLine, "{", "}", quotePos) |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
742 | self.__findBracketPosition(returnTmpLine, "[", "]", quotePos) |
7998 | 743 | except IndexError: |
744 | continue | |
745 | ||
746 | returnValue = re.sub(returnPattern, "", returnTmpLine) | |
747 | self.returnValueInBody.append(returnValue) | |
748 | ||
749 | returnFound = False | |
750 | returnTmpLine = "" |