docstripy.parse_doc#
docstripy.parse_doc.main_parser#
Global docstring parsing functions.
- parse_docstring(lines, *, add_missing=True)#
Docstring parser.
- Parameters:
- Return type:
- Returns:
ranges_docstr (List[List[int]]) – Ranges of the docstrings.
sections_list (List[Dict]) – Parsed sections.
to_insert (List[bool]) – Whether to insert a new docstring or overwrite the existing one.
- parse_all(lines_docstr)#
Parse the whole docstring.
- Parameters:
lines_docstr (List[str]) – Lines of the docstring.
- Returns:
sections – Parsed sections. Can contain the following keys:
_title (List[str])
_parameters (List[Dict])
_returns (List[Dict])
_attributes (List[Dict])
_raises (List[Dict])
any other section name found in the docstring (List[str])
- Return type:
Dict
Examples
One can parse a docstring as follows:
{ '_title': ['This is a title\n', '\n', 'This is a description\n'], '_parameters': [ { 'name': 'param1', 'type': 'int', 'optional': False, 'description': ['Description of param1\n'], }, { 'name': 'param2', 'type': 'str', 'optional': True, 'description': ['Description of param2\n'], 'default': '""', }, ], '_returns': [ { 'type': 'int', 'description': ['Description of the return\n'], }, ], 'Example': ['Example of a section\n'], }
docstripy.parse_doc.parse_params#
Parameter section parsing functions.
- parse_params_all(lines, style, section_name='param')#
Parse parameters, raises, returns, yields and attributes section.
- Parameters:
lines (List[str]) – Lines of the docstring containing parameters descriptions.
style (str) – Format style of the docstring (one of ‘numpy’, ‘google’ or ‘rest’).
section_name (str, optional) – Name of the section to parse. One of “param”, “return”, “yield”, “attribute”, “raises”. By default, “param”.
- Returns:
params_dict – Parameters dictionary with the following keys:
- typedict
Dictionary of parameter names and their types.
- optionaldict
Dictionary of parameter names and whether they are optional.
- descriptiondict
Dictionary of parameter names and their descriptions.
- defaultdict
Dictionary of parameter names and their default values.
- Return type:
Example
One can parse a docstring as follows:
[ { 'name': 'param1', 'type': 'int', 'optional': False, 'description': ['Description of param1\n'], }, { 'name': 'param2', 'type': 'str', 'optional': True, 'description': ['Description of param2\n'], 'default': '""', }, ],
docstripy.parse_doc.parse_signature#
Parse def lines (function signatures).
- parse_signature(lines)#
Parse function signature (“def …”).
docstripy.parse_doc.postprocessing#
Postprocessing functions for some sections.
docstripy.parse_doc.section_ranges#
Parse sections.
- parse_sections_ranges(lines)#
Parse sections of a docstring and detect docstring style.
- clean_section_ranges(ranges)#
Clean section ranges.
If a section is empty, remove it.
- Return type:
docstripy.parse_doc.signature#
Signature related functions.
- merge_docstr_signature(sections_docstr, lines_signature)#
Merge docstring and definition ranges.
- Return type: