Docstring Parsers¶
RestructuredText and Parameter parsers
- class Directive[source]¶
A simple Class which corresponds to reStructureText directive.
- Parameters
argument (Optional[str]) – The argument of the directive.
- property line_string: str¶
Converts the lines of the directive into a single string.
- Returns
The string of the lines.
- Return type
str
- class Param[source]¶
A simple Class which corresponds to function parameters.
- Parameters
name (str) – The name of the parameter.
description (str) – The description of the parameter.
- class CustomRstParser[source]¶
- A barebones reStructuredText parser using Regex.Can also be used in Context Manager mode.
Note
Might be switched to an AST based one in the future.
Example
>>> from scripts.utils.parsers import CustomRstParser >>> with open('README.rst') as f: ... data = f.read() >>> # As an object. >>> parser = CustomRstParser() >>> parser.parse(data) >>> print( ... parser.sections[0].to_string() ... ) >>> # As a context manager. >>> with CustomRstParser() as parser: ... parser.parse(data) ... print( ... parser.sections[0].to_string() ... ) >>> assert parser.sections == []
- info¶
Additional lines before Params.
- property parsed_params¶
Returns a list of parsed parameters.
- Returns
The parsed params.
- Return type
List[Dict[str, Any]]
- property param_names: List[str]¶
Returns a list of parsed parameter names.
- Returns
The parsed params.
- Return type
List[str]