9 |
9 |
10 |
10 |
11 def generateEricDoc(functionInfo): |
11 def generateEricDoc(functionInfo): |
12 """ |
12 """ |
13 Function to generate the docstring line list iaw. eric documentation style. |
13 Function to generate the docstring line list iaw. eric documentation style. |
14 |
14 |
15 Note: Partial English text is created with DESCRIPTION placeholders |
15 Note: Partial English text is created with DESCRIPTION placeholders |
16 for descriptions and TYPE placeholders for type information |
16 for descriptions and TYPE placeholders for type information |
17 |
17 |
18 @param functionInfo object containing the function information to base |
18 @param functionInfo object containing the function information to base |
19 the docstring on |
19 the docstring on |
20 @type FunctionInfo |
20 @type FunctionInfo |
21 @return list of docstring lines |
21 @return list of docstring lines |
22 @rtype str |
22 @rtype str |
23 """ |
23 """ |
24 # __IGNORE_WARNING_D202__ |
24 # __IGNORE_WARNING_D202__ |
25 lines = [] |
25 lines = [] |
26 |
26 |
27 # create a basic/partial function description |
27 # create a basic/partial function description |
28 if functionInfo.functionType == "classmethod": |
28 if functionInfo.functionType == "classmethod": |
29 descr = "Class method " |
29 descr = "Class method " |
30 elif functionInfo.functionType == "staticmethod": |
30 elif functionInfo.functionType == "staticmethod": |
31 descr = "Static method " |
31 descr = "Static method " |
59 elif functionInfo.functionType == "qtslot": |
60 elif functionInfo.functionType == "qtslot": |
60 descr = "Slot " |
61 descr = "Slot " |
61 else: |
62 else: |
62 descr = "Function " |
63 descr = "Function " |
63 lines.append(descr) |
64 lines.append(descr) |
64 |
65 |
65 # remove 'self', 'this' or 'cls' from arguments list |
66 # remove 'self', 'this' or 'cls' from arguments list |
66 if ( |
67 if len(functionInfo.argumentsList) > 0 and functionInfo.argumentsList[0][0] in ( |
67 len(functionInfo.argumentsList) > 0 and |
68 "self", |
68 functionInfo.argumentsList[0][0] in ("self", "cls", "this") |
69 "cls", |
|
70 "this", |
69 ): |
71 ): |
70 del functionInfo.argumentsList[0] |
72 del functionInfo.argumentsList[0] |
71 |
73 |
72 # add an empty line if there is one of the other sections |
74 # add an empty line if there is one of the other sections |
73 if ( |
75 if ( |
74 functionInfo.argumentsList or |
76 functionInfo.argumentsList |
75 functionInfo.hasYield or |
77 or functionInfo.hasYield |
76 functionInfo.returnTypeAnnotated or |
78 or functionInfo.returnTypeAnnotated |
77 functionInfo.returnValueInBody or |
79 or functionInfo.returnValueInBody |
78 functionInfo.raiseList |
80 or functionInfo.raiseList |
79 ): |
81 ): |
80 lines.append("") |
82 lines.append("") |
81 |
83 |
82 # add the parameters section |
84 # add the parameters section |
83 tag = "@param" |
85 tag = "@param" |
84 for argName, argType, argValue in functionInfo.argumentsList: |
86 for argName, argType, argValue in functionInfo.argumentsList: |
85 if argName == "*": |
87 if argName == "*": |
86 tag = "@keyparam" |
88 tag = "@keyparam" |
87 continue |
89 continue |
88 |
90 |
89 argLine = "{0} {1} DESCRIPTION".format(tag, argName) |
91 argLine = "{0} {1} DESCRIPTION".format(tag, argName) |
90 if argValue: |
92 if argValue: |
91 argLine += " (defaults to {0})".format(argValue) |
93 argLine += " (defaults to {0})".format(argValue) |
92 lines.append(argLine) |
94 lines.append(argLine) |
93 |
95 |
94 if argType is None: |
96 if argType is None: |
95 argType = "TYPE" |
97 argType = "TYPE" |
96 argLine = "@type {0}".format(argType) |
98 argLine = "@type {0}".format(argType) |
97 if argValue: |
99 if argValue: |
98 argLine += " (optional)" |
100 argLine += " (optional)" |
99 lines.append(argLine) |
101 lines.append(argLine) |
100 |
102 |
101 # add return section |
103 # add return section |
102 if ( |
104 if ( |
103 functionInfo.hasYield or |
105 functionInfo.hasYield |
104 functionInfo.returnValueInBody or |
106 or functionInfo.returnValueInBody |
105 functionInfo.returnTypeAnnotated |
107 or functionInfo.returnTypeAnnotated |
106 ): |
108 ): |
107 if functionInfo.hasYield: |
109 if functionInfo.hasYield: |
108 lines.append("@yield DESCRIPTION") |
110 lines.append("@yield DESCRIPTION") |
109 rType = "@ytype" |
111 rType = "@ytype" |
110 else: |
112 else: |
111 lines.append("@return DESCRIPTION") |
113 lines.append("@return DESCRIPTION") |
112 rType = "@rtype" |
114 rType = "@rtype" |
113 if functionInfo.returnTypeAnnotated: |
115 if functionInfo.returnTypeAnnotated: |
114 lines.append("{0} {1}".format( |
116 lines.append("{0} {1}".format(rType, functionInfo.returnTypeAnnotated)) |
115 rType, functionInfo.returnTypeAnnotated)) |
|
116 else: |
117 else: |
117 lines.append("{0} TYPE".format(rType)) |
118 lines.append("{0} TYPE".format(rType)) |
118 |
119 |
119 # add an exceptions section, if function raises something |
120 # add an exceptions section, if function raises something |
120 if functionInfo.raiseList: |
121 if functionInfo.raiseList: |
121 for exc in sorted(functionInfo.raiseList): |
122 for exc in sorted(functionInfo.raiseList): |
122 lines.append("@exception {0} DESCRIPTION".format(exc)) |
123 lines.append("@exception {0} DESCRIPTION".format(exc)) |
123 |
124 |
124 return lines |
125 return lines |