MCPcopy
hub / github.com/google/python-fire / parse

Function parse

fire/docstrings.py:118–208  ·  view source on GitHub ↗

Returns DocstringInfo about the given docstring. This parser aims to parse Google, numpy, and rst formatted docstrings. These are the three most common docstring styles at the time of this writing. This parser aims to be permissive, working even when the docstring deviates from the strict

(docstring)

Source from the content-addressed store, hash-verified

116
117
118def parse(docstring):
119 """Returns DocstringInfo about the given docstring.
120
121 This parser aims to parse Google, numpy, and rst formatted docstrings. These
122 are the three most common docstring styles at the time of this writing.
123
124 This parser aims to be permissive, working even when the docstring deviates
125 from the strict recommendations of these styles.
126
127 This parser does not aim to fully extract all structured information from a
128 docstring, since there are simply too many ways to structure information in a
129 docstring. Sometimes content will remain as unstructured text and simply gets
130 included in the description.
131
132 The Google docstring style guide is available at:
133 https://github.com/google/styleguide/blob/gh-pages/pyguide.md
134
135 The numpy docstring style guide is available at:
136 https://numpydoc.readthedocs.io/en/latest/format.html
137
138 Information about the rST docstring format is available at:
139 https://www.python.org/dev/peps/pep-0287/
140 The full set of directives such as param and type for rST docstrings are at:
141 http://www.sphinx-doc.org/en/master/usage/restructuredtext/domains.html
142
143 Note: This function does not claim to handle all docstrings well. A list of
144 limitations is available at the top of the file. It does aim to run without
145 crashing in O(n) time on all strings on length n. If you find a string that
146 causes this to crash or run unacceptably slowly, please consider submitting
147 a pull request.
148
149 Args:
150 docstring: The docstring to parse.
151
152 Returns:
153 A DocstringInfo containing information about the docstring.
154 """
155 if docstring is None:
156 return DocstringInfo()
157
158 lines = docstring.strip().split('\n')
159 lines_len = len(lines)
160 state = Namespace() # TODO(dbieber): Switch to an explicit class.
161
162 # Variables in state include:
163 state.section.title = None
164 state.section.indentation = None
165 state.section.line1_indentation = None
166 state.section.format = None
167 state.summary.permitted = True
168 state.summary.lines = []
169 state.description.lines = []
170 state.args = []
171 state.kwargs = []
172 state.current_arg = None
173 state.returns.lines = []
174 state.yields.lines = []
175 state.raises.lines = []

Callers 1

_CallAndUpdateTraceFunction · 0.85

Calls 9

DocstringInfoClass · 0.85
NamespaceClass · 0.85
_create_line_infoFunction · 0.85
_consume_lineFunction · 0.85
_strip_blank_linesFunction · 0.85
_join_linesFunction · 0.85
ArgInfoClass · 0.85
_cast_to_known_typeFunction · 0.85
KwargInfoClass · 0.85

Tested by

no test coverage detected