src/eric7/QScintilla/DocstringGenerator/NumpydocGenerator.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9486
5a8179763e38
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
10 10
11 def generateNumpyDoc(functionInfo, editor): 11 def generateNumpyDoc(functionInfo, editor):
12 """ 12 """
13 Function to generate the docstring line list iaw. NumPy documentation 13 Function to generate the docstring line list iaw. NumPy documentation
14 style. 14 style.
15 15
16 Note: Text is created with DESCRIPTION placeholders for descriptions and 16 Note: Text is created with DESCRIPTION placeholders for descriptions and
17 TYPE placeholders for type information 17 TYPE placeholders for type information
18 18
19 @param functionInfo object containing the function information to base 19 @param functionInfo object containing the function information to base
20 the docstring on 20 the docstring on
21 @type FunctionInfo 21 @type FunctionInfo
22 @param editor reference to the editor 22 @param editor reference to the editor
23 @type Editor 23 @type Editor
24 @return list of docstring lines 24 @return list of docstring lines
25 @rtype str 25 @rtype str
26 """ 26 """
27 # __IGNORE_WARNING_D202__ 27 # __IGNORE_WARNING_D202__
28 lines = [] 28 lines = []
29 29
30 # function description 30 # function description
31 lines.append("") 31 lines.append("")
32 32
33 # remove 'self', 'this' or 'cls' from arguments list 33 # remove 'self', 'this' or 'cls' from arguments list
34 if ( 34 if len(functionInfo.argumentsList) > 0 and functionInfo.argumentsList[0][0] in (
35 len(functionInfo.argumentsList) > 0 and 35 "self",
36 functionInfo.argumentsList[0][0] in ("self", "cls", "this") 36 "cls",
37 "this",
37 ): 38 ):
38 del functionInfo.argumentsList[0] 39 del functionInfo.argumentsList[0]
39 40
40 # determine additional indentation string 41 # determine additional indentation string
41 indentWidth = editor.indentationWidth() 42 indentWidth = editor.indentationWidth()
42 if indentWidth == 0: 43 if indentWidth == 0:
43 indentWidth = editor.tabWidth() 44 indentWidth = editor.tabWidth()
44 indent = indentWidth * " " 45 indent = indentWidth * " "
45 46
46 # add the parameters section 47 # add the parameters section
47 if functionInfo.argumentsList: 48 if functionInfo.argumentsList:
48 lines.append("") 49 lines.append("")
49 lines.append("Parameters") 50 lines.append("Parameters")
50 lines.append("----------") 51 lines.append("----------")
59 lines.append(argLine) 60 lines.append(argLine)
60 argLine = "{0}DESCRIPTION.".format(indent) 61 argLine = "{0}DESCRIPTION.".format(indent)
61 if argValue: 62 if argValue:
62 argLine += " The default is {0}".format(argValue) 63 argLine += " The default is {0}".format(argValue)
63 lines.append(argLine) 64 lines.append(argLine)
64 65
65 # add an exceptions section, if function raises something 66 # add an exceptions section, if function raises something
66 if functionInfo.raiseList: 67 if functionInfo.raiseList:
67 lines.append("") 68 lines.append("")
68 lines.append("Raises") 69 lines.append("Raises")
69 lines.append("------") 70 lines.append("------")
70 for exc in sorted(functionInfo.raiseList): 71 for exc in sorted(functionInfo.raiseList):
71 lines.append("{0}".format(exc)) 72 lines.append("{0}".format(exc))
72 lines.append("{0}DESCRIPTION".format(indent)) 73 lines.append("{0}DESCRIPTION".format(indent))
73 74
74 # add return section 75 # add return section
75 lines.append("") 76 lines.append("")
76 if functionInfo.hasYield: 77 if functionInfo.hasYield:
77 lines.append("Yields") 78 lines.append("Yields")
78 lines.append("------") 79 lines.append("------")
85 elif functionInfo.returnValueInBody: 86 elif functionInfo.returnValueInBody:
86 lines.append("TYPE") 87 lines.append("TYPE")
87 lines.append("{0}DESCRIPTION.".format(indent)) 88 lines.append("{0}DESCRIPTION.".format(indent))
88 else: 89 else:
89 lines.append("{0}None".format(indent)) 90 lines.append("{0}None".format(indent))
90 91
91 return lines 92 return lines

eric ide

mercurial