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 the docstring generator for the 'ericdoc' style. | |
8 | """ | |
9 | ||
10 | ||
11 | def generateEricDoc(functionInfo): | |
12 | """ | |
13 | Function to generate the docstring line list iaw. eric documentation style. | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
14 | |
7998 | 15 | Note: Partial English text is created with DESCRIPTION placeholders |
16 | for descriptions and TYPE placeholders for type information | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
17 | |
7998 | 18 | @param functionInfo object containing the function information to base |
19 | the docstring on | |
20 | @type FunctionInfo | |
21 | @return list of docstring lines | |
22 | @rtype str | |
23 | """ | |
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
|
24 | # __IGNORE_WARNING_D202__ |
7998 | 25 | lines = [] |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
26 | |
7998 | 27 | # create a basic/partial function description |
28 | if functionInfo.functionType == "classmethod": | |
29 | descr = "Class method " | |
30 | elif functionInfo.functionType == "staticmethod": | |
31 | descr = "Static method " | |
32 | elif functionInfo.functionType == "constructor": | |
33 | descr = "Constructor" | |
34 | else: | |
35 | if functionInfo.visibility == "public": | |
36 | descr = "Public " | |
37 | elif functionInfo.visibility == "protected": | |
38 | descr = "Protected " | |
39 | elif functionInfo.visibility == "private": | |
40 | descr = "Private " | |
41 | elif functionInfo.visibility == "special": | |
42 | descr = "Special " | |
43 | else: | |
44 | descr = "" | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
45 | |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
46 | if len(functionInfo.argumentsList) > 0 and functionInfo.argumentsList[0][0] in ( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
47 | "self", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
48 | "cls", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
49 | "this", |
7998 | 50 | ): |
51 | if functionInfo.isAsync: | |
52 | descr += "coroutine " | |
53 | elif functionInfo.functionType == "qtslot": | |
54 | descr += "slot " | |
55 | else: | |
56 | descr += "method " | |
57 | else: | |
58 | if functionInfo.isAsync: | |
59 | descr = "Coroutine " | |
60 | elif functionInfo.functionType == "qtslot": | |
61 | descr = "Slot " | |
62 | else: | |
63 | descr = "Function " | |
64 | lines.append(descr) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
65 | |
7998 | 66 | # remove 'self', 'this' or 'cls' from arguments list |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
67 | if len(functionInfo.argumentsList) > 0 and functionInfo.argumentsList[0][0] in ( |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
68 | "self", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
69 | "cls", |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
70 | "this", |
7998 | 71 | ): |
72 | del functionInfo.argumentsList[0] | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
73 | |
7998 | 74 | # add an empty line if there is one of the other sections |
75 | if ( | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
76 | functionInfo.argumentsList |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
77 | or functionInfo.hasYield |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
78 | or functionInfo.returnTypeAnnotated |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
79 | or functionInfo.returnValueInBody |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
80 | or functionInfo.raiseList |
7998 | 81 | ): |
82 | lines.append("") | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
83 | |
7998 | 84 | # add the parameters section |
85 | tag = "@param" | |
86 | for argName, argType, argValue in functionInfo.argumentsList: | |
87 | if argName == "*": | |
88 | tag = "@keyparam" | |
89 | continue | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
90 | |
7998 | 91 | argLine = "{0} {1} DESCRIPTION".format(tag, argName) |
92 | if argValue: | |
93 | argLine += " (defaults to {0})".format(argValue) | |
94 | lines.append(argLine) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
95 | |
7998 | 96 | if argType is None: |
97 | argType = "TYPE" | |
98 | argLine = "@type {0}".format(argType) | |
99 | if argValue: | |
100 | argLine += " (optional)" | |
101 | lines.append(argLine) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
102 | |
7998 | 103 | # add return section |
8005
94a6a1bd5f80
Docstring: corrected the return section generation for ericdoc and sphinxdoc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8000
diff
changeset
|
104 | if ( |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
105 | functionInfo.hasYield |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
106 | or functionInfo.returnValueInBody |
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
107 | or functionInfo.returnTypeAnnotated |
8005
94a6a1bd5f80
Docstring: corrected the return section generation for ericdoc and sphinxdoc.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8000
diff
changeset
|
108 | ): |
7998 | 109 | if functionInfo.hasYield: |
110 | lines.append("@yield DESCRIPTION") | |
111 | rType = "@ytype" | |
112 | else: | |
113 | lines.append("@return DESCRIPTION") | |
114 | rType = "@rtype" | |
115 | if functionInfo.returnTypeAnnotated: | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
116 | lines.append("{0} {1}".format(rType, functionInfo.returnTypeAnnotated)) |
7998 | 117 | else: |
118 | lines.append("{0} TYPE".format(rType)) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
119 | |
7998 | 120 | # add an exceptions section, if function raises something |
121 | if functionInfo.raiseList: | |
122 | for exc in sorted(functionInfo.raiseList): | |
123 | lines.append("@exception {0} DESCRIPTION".format(exc)) | |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
124 | |
7998 | 125 | return lines |