eric6/QScintilla/DocstringGenerator/NumpydocGenerator.py

changeset 7998
cd41c844862f
child 8000
47b15df088e4
equal deleted inserted replaced
7997:2ca23396c25c 7998:cd41c844862f
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2021 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the docstring generator for the 'numpydoc' style.
8 """
9
10
11 def generateNumpyDoc(functionInfo, editor):
12 """
13 Function to generate the docstring line list iaw. NumPy documentation
14 style.
15
16 Note: Text is created with DESCRIPTION placeholders for descriptions and
17 TYPE placeholders for type information
18
19 @param functionInfo object containing the function information to base
20 the docstring on
21 @type FunctionInfo
22 @param editor reference to the editor
23 @type Editor
24 @return list of docstring lines
25 @rtype str
26 """
27 lines = []
28
29 # function description
30 lines.append("DESCRIPTION")
31
32 # remove 'self', 'this' or 'cls' from arguments list
33 if (
34 len(functionInfo.argumentsList) > 0 and
35 functionInfo.argumentsList[0][0] in ("self", "cls", "this")
36 ):
37 del functionInfo.argumentsList[0]
38
39 # determine additional indentation string
40 indentWidth = editor.indentationWidth()
41 if indentWidth == 0:
42 indentWidth = editor.tabWidth()
43 indent = indentWidth * " "
44
45 # add the parameters section
46 if functionInfo.argumentsList:
47 lines.append("")
48 lines.append("Parameters")
49 lines.append("----------")
50 for argName, argType, argValue in functionInfo.argumentsList:
51 argLine = "{0} : ".format(argName)
52 if argType:
53 argLine += "{0}".format(argType)
54 else:
55 argLine += "TYPE"
56 if argValue:
57 argLine += ", optional"
58 lines.append(argLine)
59 argLine = "{0}DESCRIPTION.".format(indent)
60 if argValue:
61 argLine += " The default is {0}".format(argValue)
62 lines.append(argLine)
63
64 # add an exceptions section, if function raises something
65 if functionInfo.raiseList:
66 lines.append("")
67 lines.append("Raises")
68 lines.append("------")
69 for exc in sorted(functionInfo.raiseList):
70 lines.append("{0}".format(exc))
71 lines.append("{0}DESCRIPTION".format(indent))
72
73 # add return section
74 lines.append("")
75 if functionInfo.hasYield:
76 lines.append("Yields")
77 lines.append("------")
78 else:
79 lines.append("Returns")
80 lines.append("-------")
81 if functionInfo.returnTypeAnnotated:
82 lines.append("{0}".format(functionInfo.returnTypeAnnotated))
83 lines.append("{0}DESCRIPTION.".format(indent))
84 elif functionInfo.returnValueInBody:
85 lines.append("TYPE")
86 lines.append("{0}DESCRIPTION.".format(indent))
87 else:
88 lines.append("{0}None".format(indent))
89
90 return lines

eric ide

mercurial