eric6/Documentation/Source/eric6.QScintilla.DocstringGenerator.PyDocstringGenerator.html

changeset 7998
cd41c844862f
child 8000
47b15df088e4
equal deleted inserted replaced
7997:2ca23396c25c 7998:cd41c844862f
1 <!DOCTYPE html>
2 <html><head>
3 <title>eric6.QScintilla.DocstringGenerator.PyDocstringGenerator</title>
4 <meta charset="UTF-8">
5 <style>
6 body {
7 background: #EDECE6;
8 margin: 0em 1em 10em 1em;
9 color: black;
10 }
11
12 h1 { color: white; background: #85774A; }
13 h2 { color: white; background: #85774A; }
14 h3 { color: white; background: #9D936E; }
15 h4 { color: white; background: #9D936E; }
16
17 a { color: #BA6D36; }
18
19 </style>
20 </head>
21 <body>
22 <a NAME="top" ID="top"></a>
23 <h1>eric6.QScintilla.DocstringGenerator.PyDocstringGenerator</h1>
24
25 <p>
26 Module implementing a docstring generator for Python.
27 </p>
28 <h3>Global Attributes</h3>
29
30 <table>
31 <tr><td>None</td></tr>
32 </table>
33 <h3>Classes</h3>
34
35 <table>
36
37 <tr>
38 <td><a href="#PyDocstringGenerator">PyDocstringGenerator</a></td>
39 <td>Class implementing a docstring generator for Python.</td>
40 </tr>
41 <tr>
42 <td><a href="#PyFunctionInfo">PyFunctionInfo</a></td>
43 <td>Class implementing an object to extract and store function information.</td>
44 </tr>
45 </table>
46 <h3>Functions</h3>
47
48 <table>
49 <tr><td>None</td></tr>
50 </table>
51 <hr />
52 <hr />
53 <a NAME="PyDocstringGenerator" ID="PyDocstringGenerator"></a>
54 <h2>PyDocstringGenerator</h2>
55
56 <p>
57 Class implementing a docstring generator for Python.
58 </p>
59 <h3>Derived from</h3>
60 BaseDocstringGenerator
61 <h3>Class Attributes</h3>
62
63 <table>
64 <tr><td>None</td></tr>
65 </table>
66 <h3>Class Methods</h3>
67
68 <table>
69 <tr><td>None</td></tr>
70 </table>
71 <h3>Methods</h3>
72
73 <table>
74
75 <tr>
76 <td><a href="#PyDocstringGenerator.__init__">PyDocstringGenerator</a></td>
77 <td>Constructor</td>
78 </tr>
79 <tr>
80 <td><a href="#PyDocstringGenerator.__generateDocstring">__generateDocstring</a></td>
81 <td>Private method to generate the list of docstring lines.</td>
82 </tr>
83 <tr>
84 <td><a href="#PyDocstringGenerator.__generateDocstringFromBelow">__generateDocstringFromBelow</a></td>
85 <td>Private method to generate a docstring when the gicen position is on the line below the end of the definition.</td>
86 </tr>
87 <tr>
88 <td><a href="#PyDocstringGenerator.__generateDocstringFromStart">__generateDocstringFromStart</a></td>
89 <td>Private method to generate a docstring based on the cursor being placed on the first line of the definition.</td>
90 </tr>
91 <tr>
92 <td><a href="#PyDocstringGenerator.__getFunctionBody">__getFunctionBody</a></td>
93 <td>Private method to get the function body.</td>
94 </tr>
95 <tr>
96 <td><a href="#PyDocstringGenerator.__getFunctionDefinitionFromBelow">__getFunctionDefinitionFromBelow</a></td>
97 <td>Private method to extract the function definition based on the cursor being placed on the first line after the definition.</td>
98 </tr>
99 <tr>
100 <td><a href="#PyDocstringGenerator.__getFunctionDefinitionFromStart">__getFunctionDefinitionFromStart</a></td>
101 <td>Private method to extract the function definition based on the cursor being placed on the first line of the definition.</td>
102 </tr>
103 <tr>
104 <td><a href="#PyDocstringGenerator.__getIndentationInsertString">__getIndentationInsertString</a></td>
105 <td>Private method to create the indentation string for the docstring.</td>
106 </tr>
107 <tr>
108 <td><a href="#PyDocstringGenerator.__isTripleQuotesStart">__isTripleQuotesStart</a></td>
109 <td>Private method to test, if the given text is the start of a triple quoted string.</td>
110 </tr>
111 <tr>
112 <td><a href="#PyDocstringGenerator.hasFunctionDefinition">hasFunctionDefinition</a></td>
113 <td>Public method to test, if the cursor is right below a function definition.</td>
114 </tr>
115 <tr>
116 <td><a href="#PyDocstringGenerator.insertDocstring">insertDocstring</a></td>
117 <td>Public method to insert a docstring for the function at the cursor position.</td>
118 </tr>
119 <tr>
120 <td><a href="#PyDocstringGenerator.isDocstringIntro">isDocstringIntro</a></td>
121 <td>Public function to test, if the line up to the cursor position might be introducing a docstring.</td>
122 </tr>
123 <tr>
124 <td><a href="#PyDocstringGenerator.isFunctionStart">isFunctionStart</a></td>
125 <td>Public method to test, if a text is the start of a function or method definition.</td>
126 </tr>
127 </table>
128 <h3>Static Methods</h3>
129
130 <table>
131 <tr><td>None</td></tr>
132 </table>
133
134 <a NAME="PyDocstringGenerator.__init__" ID="PyDocstringGenerator.__init__"></a>
135 <h4>PyDocstringGenerator (Constructor)</h4>
136 <b>PyDocstringGenerator</b>(<i>editor</i>)
137
138 <p>
139 Constructor
140 </p>
141 <dl>
142
143 <dt><i>editor</i> (Editor)</dt>
144 <dd>
145 reference to the editor widget
146 </dd>
147 </dl>
148 <a NAME="PyDocstringGenerator.__generateDocstring" ID="PyDocstringGenerator.__generateDocstring"></a>
149 <h4>PyDocstringGenerator.__generateDocstring</h4>
150 <b>__generateDocstring</b>(<i>quote, functionDef, bodyStartLine</i>)
151
152 <p>
153 Private method to generate the list of docstring lines.
154 </p>
155 <dl>
156
157 <dt><i>quote</i> (str)</dt>
158 <dd>
159 quote string
160 </dd>
161 <dt><i>functionDef</i> (str)</dt>
162 <dd>
163 text containing the function definition
164 </dd>
165 <dt><i>bodyStartLine</i> (int)</dt>
166 <dd>
167 starting line of the function body
168 </dd>
169 </dl>
170 <dl>
171 <dt>Return:</dt>
172 <dd>
173 list of docstring lines
174 </dd>
175 </dl>
176 <dl>
177 <dt>Return Type:</dt>
178 <dd>
179 list of str
180 </dd>
181 </dl>
182 <a NAME="PyDocstringGenerator.__generateDocstringFromBelow" ID="PyDocstringGenerator.__generateDocstringFromBelow"></a>
183 <h4>PyDocstringGenerator.__generateDocstringFromBelow</h4>
184 <b>__generateDocstringFromBelow</b>(<i>cursorPosition</i>)
185
186 <p>
187 Private method to generate a docstring when the gicen position is on
188 the line below the end of the definition.
189 </p>
190 <dl>
191
192 <dt><i>cursorPosition</i> (tuple of (int, int))</dt>
193 <dd>
194 position of the cursor (line and index)
195 </dd>
196 </dl>
197 <dl>
198 <dt>Return:</dt>
199 <dd>
200 tuple containing the docstring and a tuple containing the
201 insertion line and index
202 </dd>
203 </dl>
204 <dl>
205 <dt>Return Type:</dt>
206 <dd>
207 tuple of (str, tuple(int, int))
208 </dd>
209 </dl>
210 <a NAME="PyDocstringGenerator.__generateDocstringFromStart" ID="PyDocstringGenerator.__generateDocstringFromStart"></a>
211 <h4>PyDocstringGenerator.__generateDocstringFromStart</h4>
212 <b>__generateDocstringFromStart</b>(<i></i>)
213
214 <p>
215 Private method to generate a docstring based on the cursor being
216 placed on the first line of the definition.
217 </p>
218 <dl>
219 <dt>Return:</dt>
220 <dd>
221 tuple containing the docstring and a tuple containing the
222 insertion line and index
223 </dd>
224 </dl>
225 <dl>
226 <dt>Return Type:</dt>
227 <dd>
228 tuple of (str, tuple(int, int))
229 </dd>
230 </dl>
231 <a NAME="PyDocstringGenerator.__getFunctionBody" ID="PyDocstringGenerator.__getFunctionBody"></a>
232 <h4>PyDocstringGenerator.__getFunctionBody</h4>
233 <b>__getFunctionBody</b>(<i>functionIndent, startLine</i>)
234
235 <p>
236 Private method to get the function body.
237 </p>
238 <dl>
239
240 <dt><i>functionIndent</i> (str)</dt>
241 <dd>
242 indentation string of the function definition
243 </dd>
244 <dt><i>startLine</i> (int)</dt>
245 <dd>
246 starting line for the extraction process
247 </dd>
248 </dl>
249 <dl>
250 <dt>Return:</dt>
251 <dd>
252 text containing the function body
253 </dd>
254 </dl>
255 <dl>
256 <dt>Return Type:</dt>
257 <dd>
258 str
259 </dd>
260 </dl>
261 <a NAME="PyDocstringGenerator.__getFunctionDefinitionFromBelow" ID="PyDocstringGenerator.__getFunctionDefinitionFromBelow"></a>
262 <h4>PyDocstringGenerator.__getFunctionDefinitionFromBelow</h4>
263 <b>__getFunctionDefinitionFromBelow</b>(<i>cursorPosition</i>)
264
265 <p>
266 Private method to extract the function definition based on the cursor
267 being placed on the first line after the definition.
268 </p>
269 <dl>
270
271 <dt><i>cursorPosition</i> (tuple of (int, int))</dt>
272 <dd>
273 current cursor position (line and column)
274 </dd>
275 </dl>
276 <dl>
277 <dt>Return:</dt>
278 <dd>
279 text containing the function definition
280 </dd>
281 </dl>
282 <dl>
283 <dt>Return Type:</dt>
284 <dd>
285 str
286 </dd>
287 </dl>
288 <a NAME="PyDocstringGenerator.__getFunctionDefinitionFromStart" ID="PyDocstringGenerator.__getFunctionDefinitionFromStart"></a>
289 <h4>PyDocstringGenerator.__getFunctionDefinitionFromStart</h4>
290 <b>__getFunctionDefinitionFromStart</b>(<i></i>)
291
292 <p>
293 Private method to extract the function definition based on the cursor
294 being placed on the first line of the definition.
295 </p>
296 <dl>
297 <dt>Return:</dt>
298 <dd>
299 text containing the function definition
300 </dd>
301 </dl>
302 <dl>
303 <dt>Return Type:</dt>
304 <dd>
305 str
306 </dd>
307 </dl>
308 <a NAME="PyDocstringGenerator.__getIndentationInsertString" ID="PyDocstringGenerator.__getIndentationInsertString"></a>
309 <h4>PyDocstringGenerator.__getIndentationInsertString</h4>
310 <b>__getIndentationInsertString</b>(<i>text</i>)
311
312 <p>
313 Private method to create the indentation string for the docstring.
314 </p>
315 <dl>
316
317 <dt><i>text</i> (str)</dt>
318 <dd>
319 text to based the indentation on
320 </dd>
321 </dl>
322 <dl>
323 <dt>Return:</dt>
324 <dd>
325 indentation string for docstring
326 </dd>
327 </dl>
328 <dl>
329 <dt>Return Type:</dt>
330 <dd>
331 str
332 </dd>
333 </dl>
334 <a NAME="PyDocstringGenerator.__isTripleQuotesStart" ID="PyDocstringGenerator.__isTripleQuotesStart"></a>
335 <h4>PyDocstringGenerator.__isTripleQuotesStart</h4>
336 <b>__isTripleQuotesStart</b>(<i>text</i>)
337
338 <p>
339 Private method to test, if the given text is the start of a triple
340 quoted string.
341 </p>
342 <dl>
343
344 <dt><i>text</i> (str)</dt>
345 <dd>
346 text to be inspected
347 </dd>
348 </dl>
349 <dl>
350 <dt>Return:</dt>
351 <dd>
352 flag indicating a triple quote start
353 </dd>
354 </dl>
355 <dl>
356 <dt>Return Type:</dt>
357 <dd>
358 bool
359 </dd>
360 </dl>
361 <a NAME="PyDocstringGenerator.hasFunctionDefinition" ID="PyDocstringGenerator.hasFunctionDefinition"></a>
362 <h4>PyDocstringGenerator.hasFunctionDefinition</h4>
363 <b>hasFunctionDefinition</b>(<i>cursorPosition</i>)
364
365 <p>
366 Public method to test, if the cursor is right below a function
367 definition.
368 </p>
369 <dl>
370
371 <dt><i>cursorPosition</i> (tuple of (int, int))</dt>
372 <dd>
373 current cursor position (line and column)
374 </dd>
375 </dl>
376 <dl>
377 <dt>Return:</dt>
378 <dd>
379 flag indicating cursor is right below a function definition
380 </dd>
381 </dl>
382 <dl>
383 <dt>Return Type:</dt>
384 <dd>
385 bool
386 </dd>
387 </dl>
388 <a NAME="PyDocstringGenerator.insertDocstring" ID="PyDocstringGenerator.insertDocstring"></a>
389 <h4>PyDocstringGenerator.insertDocstring</h4>
390 <b>insertDocstring</b>(<i>cursorPosition, fromStart=True</i>)
391
392 <p>
393 Public method to insert a docstring for the function at the cursor
394 position.
395 </p>
396 <dl>
397
398 <dt><i>cursorPosition</i> (tuple of (int, int))</dt>
399 <dd>
400 position of the cursor (line and index)
401 </dd>
402 <dt><i>fromStart</i> (bool)</dt>
403 <dd>
404 flag indicating that the editor text cursor is placed
405 on the line starting the function definition
406 </dd>
407 </dl>
408 <a NAME="PyDocstringGenerator.isDocstringIntro" ID="PyDocstringGenerator.isDocstringIntro"></a>
409 <h4>PyDocstringGenerator.isDocstringIntro</h4>
410 <b>isDocstringIntro</b>(<i>cursorPosition</i>)
411
412 <p>
413 Public function to test, if the line up to the cursor position might be
414 introducing a docstring.
415 </p>
416 <dl>
417
418 <dt><i>cursorPosition</i> (tuple of (int, int))</dt>
419 <dd>
420 current cursor position (line and column)
421 </dd>
422 </dl>
423 <dl>
424 <dt>Return:</dt>
425 <dd>
426 flag indicating a potential start of a docstring
427 </dd>
428 </dl>
429 <dl>
430 <dt>Return Type:</dt>
431 <dd>
432 bool
433 </dd>
434 </dl>
435 <a NAME="PyDocstringGenerator.isFunctionStart" ID="PyDocstringGenerator.isFunctionStart"></a>
436 <h4>PyDocstringGenerator.isFunctionStart</h4>
437 <b>isFunctionStart</b>(<i>text</i>)
438
439 <p>
440 Public method to test, if a text is the start of a function or method
441 definition.
442 </p>
443 <dl>
444
445 <dt><i>text</i> (str)</dt>
446 <dd>
447 line of text to be tested
448 </dd>
449 </dl>
450 <dl>
451 <dt>Return:</dt>
452 <dd>
453 flag indicating that the given text starts a function or
454 method definition
455 </dd>
456 </dl>
457 <dl>
458 <dt>Return Type:</dt>
459 <dd>
460 bool
461 </dd>
462 </dl>
463 <div align="right"><a href="#top">Up</a></div>
464 <hr />
465 <hr />
466 <a NAME="PyFunctionInfo" ID="PyFunctionInfo"></a>
467 <h2>PyFunctionInfo</h2>
468
469 <p>
470 Class implementing an object to extract and store function information.
471 </p>
472 <h3>Derived from</h3>
473 FunctionInfo
474 <h3>Class Attributes</h3>
475
476 <table>
477 <tr><td>None</td></tr>
478 </table>
479 <h3>Class Methods</h3>
480
481 <table>
482 <tr><td>None</td></tr>
483 </table>
484 <h3>Methods</h3>
485
486 <table>
487
488 <tr>
489 <td><a href="#PyFunctionInfo.__init__">PyFunctionInfo</a></td>
490 <td>Constructor</td>
491 </tr>
492 <tr>
493 <td><a href="#PyFunctionInfo.__findBracketPosition">__findBracketPosition</a></td>
494 <td>Private method to find the start and end position of pairs of brackets.</td>
495 </tr>
496 <tr>
497 <td><a href="#PyFunctionInfo.__findQuotePosition">__findQuotePosition</a></td>
498 <td>Private method to find the start and end position of pairs of quotes.</td>
499 </tr>
500 <tr>
501 <td><a href="#PyFunctionInfo.__isCharInPairs">__isCharInPairs</a></td>
502 <td>Private method to test, if the given character position is between pairs of brackets or quotes.</td>
503 </tr>
504 <tr>
505 <td><a href="#PyFunctionInfo.__splitArgumentToNameTypeValue">__splitArgumentToNameTypeValue</a></td>
506 <td>Private method to split some argument text to name, type and value.</td>
507 </tr>
508 <tr>
509 <td><a href="#PyFunctionInfo.__splitArgumentsTextToList">__splitArgumentsTextToList</a></td>
510 <td>Private method to split the given arguments text into a list of arguments.</td>
511 </tr>
512 <tr>
513 <td><a href="#PyFunctionInfo.parseBody">parseBody</a></td>
514 <td>Public method to parse the function body text.</td>
515 </tr>
516 <tr>
517 <td><a href="#PyFunctionInfo.parseDefinition">parseDefinition</a></td>
518 <td>Public method to parse the function definition text.</td>
519 </tr>
520 </table>
521 <h3>Static Methods</h3>
522
523 <table>
524 <tr><td>None</td></tr>
525 </table>
526
527 <a NAME="PyFunctionInfo.__init__" ID="PyFunctionInfo.__init__"></a>
528 <h4>PyFunctionInfo (Constructor)</h4>
529 <b>PyFunctionInfo</b>(<i></i>)
530
531 <p>
532 Constructor
533 </p>
534 <a NAME="PyFunctionInfo.__findBracketPosition" ID="PyFunctionInfo.__findBracketPosition"></a>
535 <h4>PyFunctionInfo.__findBracketPosition</h4>
536 <b>__findBracketPosition</b>(<i>text, bracketLeft, bracketRight, posQuote</i>)
537
538 <p>
539 Private method to find the start and end position of pairs of brackets.
540 </p>
541 <p>
542 https://stackoverflow.com/questions/29991917/
543 indices-of-matching-parentheses-in-python
544 </p>
545 <dl>
546
547 <dt><i>text</i> (str)</dt>
548 <dd>
549 text to be parsed
550 </dd>
551 <dt><i>bracketLeft</i> (str)</dt>
552 <dd>
553 character of the left bracket
554 </dd>
555 <dt><i>bracketRight</i> (str)</dt>
556 <dd>
557 character of the right bracket
558 </dd>
559 <dt><i>posQuote</i> (list of tuple of (int, int))</dt>
560 <dd>
561 list of tuple with start and end position of pairs
562 of quotes
563 </dd>
564 </dl>
565 <dl>
566 <dt>Return:</dt>
567 <dd>
568 list of tuple with start and end position of pairs of brackets
569 </dd>
570 </dl>
571 <dl>
572 <dt>Return Type:</dt>
573 <dd>
574 list of tuple of (int, int)
575 </dd>
576 </dl>
577 <dl>
578
579 <dt>Raises <b>IndexError</b>:</dt>
580 <dd>
581 raised when a closing or opening bracket is
582 missing
583 </dd>
584 </dl>
585 <a NAME="PyFunctionInfo.__findQuotePosition" ID="PyFunctionInfo.__findQuotePosition"></a>
586 <h4>PyFunctionInfo.__findQuotePosition</h4>
587 <b>__findQuotePosition</b>(<i>text</i>)
588
589 <p>
590 Private method to find the start and end position of pairs of quotes.
591 </p>
592 <dl>
593
594 <dt><i>text</i> (str)</dt>
595 <dd>
596 text to be parsed
597 </dd>
598 </dl>
599 <dl>
600 <dt>Return:</dt>
601 <dd>
602 list of tuple with start and end position of pairs of quotes
603 </dd>
604 </dl>
605 <dl>
606 <dt>Return Type:</dt>
607 <dd>
608 list of tuple of (int, int)
609 </dd>
610 </dl>
611 <dl>
612
613 <dt>Raises <b>IndexError</b>:</dt>
614 <dd>
615 raised when a matching close quote is missing
616 </dd>
617 </dl>
618 <a NAME="PyFunctionInfo.__isCharInPairs" ID="PyFunctionInfo.__isCharInPairs"></a>
619 <h4>PyFunctionInfo.__isCharInPairs</h4>
620 <b>__isCharInPairs</b>(<i>posChar, pairs</i>)
621
622 <p>
623 Private method to test, if the given character position is between
624 pairs of brackets or quotes.
625 </p>
626 <dl>
627
628 <dt><i>posChar</i> (int)</dt>
629 <dd>
630 character position to be tested
631 </dd>
632 <dt><i>pairs</i> (list of tuple of (int, int))</dt>
633 <dd>
634 list containing pairs of positions
635 </dd>
636 </dl>
637 <dl>
638 <dt>Return:</dt>
639 <dd>
640 flag indicating the position is in between
641 </dd>
642 </dl>
643 <dl>
644 <dt>Return Type:</dt>
645 <dd>
646 bool
647 </dd>
648 </dl>
649 <a NAME="PyFunctionInfo.__splitArgumentToNameTypeValue" ID="PyFunctionInfo.__splitArgumentToNameTypeValue"></a>
650 <h4>PyFunctionInfo.__splitArgumentToNameTypeValue</h4>
651 <b>__splitArgumentToNameTypeValue</b>(<i>argumentsList, quote, quoteReplace</i>)
652
653 <p>
654 Private method to split some argument text to name, type and value.
655 </p>
656 <dl>
657
658 <dt><i>argumentsList</i> (list of str)</dt>
659 <dd>
660 list of function argument definitions
661 </dd>
662 <dt><i>quote</i> (str)</dt>
663 <dd>
664 quote string to be replaced
665 </dd>
666 <dt><i>quoteReplace</i> (str)</dt>
667 <dd>
668 quote string to replace the original
669 </dd>
670 </dl>
671 <a NAME="PyFunctionInfo.__splitArgumentsTextToList" ID="PyFunctionInfo.__splitArgumentsTextToList"></a>
672 <h4>PyFunctionInfo.__splitArgumentsTextToList</h4>
673 <b>__splitArgumentsTextToList</b>(<i>argumentsText</i>)
674
675 <p>
676 Private method to split the given arguments text into a list of
677 arguments.
678 </p>
679 <p>
680 This function uses a comma to separate arguments and ignores a comma in
681 brackets and quotes.
682 </p>
683 <dl>
684
685 <dt><i>argumentsText</i> (str)</dt>
686 <dd>
687 text containing the list of arguments
688 </dd>
689 </dl>
690 <dl>
691 <dt>Return:</dt>
692 <dd>
693 list of individual argument texts
694 </dd>
695 </dl>
696 <dl>
697 <dt>Return Type:</dt>
698 <dd>
699 list of str
700 </dd>
701 </dl>
702 <a NAME="PyFunctionInfo.parseBody" ID="PyFunctionInfo.parseBody"></a>
703 <h4>PyFunctionInfo.parseBody</h4>
704 <b>parseBody</b>(<i>text</i>)
705
706 <p>
707 Public method to parse the function body text.
708 </p>
709 <dl>
710
711 <dt><i>text</i> (str)</dt>
712 <dd>
713 function body text
714 </dd>
715 </dl>
716 <a NAME="PyFunctionInfo.parseDefinition" ID="PyFunctionInfo.parseDefinition"></a>
717 <h4>PyFunctionInfo.parseDefinition</h4>
718 <b>parseDefinition</b>(<i>text, quote, quoteReplace</i>)
719
720 <p>
721 Public method to parse the function definition text.
722 </p>
723 <dl>
724
725 <dt><i>text</i> (str)</dt>
726 <dd>
727 text containing the function definition
728 </dd>
729 <dt><i>quote</i> (str)</dt>
730 <dd>
731 quote string to be replaced
732 </dd>
733 <dt><i>quoteReplace</i> (str)</dt>
734 <dd>
735 quote string to replace the original
736 </dd>
737 </dl>
738 <div align="right"><a href="#top">Up</a></div>
739 <hr />
740 </body></html>

eric ide

mercurial