class documentation

class GoogleDocstring:

Known subclasses: pydoctor.napoleon.docstring.NumpyDocstring

View In Hierarchy

Convert Google style docstrings to reStructuredText.

Example

>>> from pydoctor.napoleon import GoogleDocstring
>>> docstring = '''One line summary.
...
... Extended description.
...
... Args:
...   arg1(int): Description of `arg1`
...   arg2(str): Description of `arg2`
... Returns:
...   str: Description of return value.
... '''
>>> print(GoogleDocstring(docstring))
One line summary.

Extended description.

:param arg1: Description of `arg1`
:type arg1: int
:param arg2: Description of `arg2`
:type arg2: str

:returns: Description of return value.
:returntype: str
>>> print(GoogleDocstring(docstring, process_type_fields=True))
One line summary.

Extended description.

:param arg1: Description of `arg1`
:type arg1: `int`
:param arg2: Description of `arg2`
:type arg2: `str`

:returns: Description of return value.
:returntype: `str`
Method __init__ No summary
Method __str__ Return the parsed docstring in reStructuredText format.
Method lines Return the parsed lines of the docstring in reStructuredText format.
Instance Variable warnings Warning messages triggered during the conversion.
Method ​_consume​_contiguous Undocumented
Method ​_consume​_empty Undocumented
Method ​_consume​_field Undocumented
Method ​_consume​_fields Undocumented
Method ​_consume​_indented​_block Undocumented
Method ​_consume​_inline​_attribute Undocumented
Method ​_consume​_returns​_section Undocumented
Method ​_consume​_section​_header Undocumented
Method ​_consume​_to​_end Undocumented
Method ​_consume​_to​_next​_section Undocumented
Method ​_convert​_type Tokenize the string type and convert it with additional markup and auto linking, with L{TypeDocstring}.
Method ​_dedent Undocumented
Method ​_escape​_args​_and​_kwargs Undocumented
Method ​_fix​_field​_desc Undocumented
Method ​_format​_admonition Undocumented
Method ​_format​_block Undocumented
Method ​_format​_docutils​_params Undocumented
Method ​_format​_field Undocumented
Method ​_format​_fields Undocumented
Method ​_get​_current​_indent Undocumented
Method ​_get​_indent Undocumented
Method ​_get​_initial​_indent Undocumented
Method ​_get​_min​_indent Undocumented
Method ​_indent Undocumented
Method ​_is​_indented Undocumented
Method ​_is​_list Undocumented
Method ​_is​_section​_break Undocumented
Method ​_is​_section​_header Undocumented
Method ​_parse Undocumented
Method ​_parse​_admonition Undocumented
Method ​_parse​_attribute​_docstring Undocumented
Method ​_parse​_attributes​_section Undocumented
Method ​_parse​_examples​_section Undocumented
Method ​_parse​_generic​_section Undocumented
Method ​_parse​_keyword​_arguments​_section Undocumented
Method ​_parse​_methods​_section Undocumented
Method ​_parse​_notes​_section Undocumented
Method ​_parse​_parameters​_section Undocumented
Method ​_parse​_raises​_section Undocumented
Method ​_parse​_references​_section Undocumented
Method ​_parse​_returns​_section Undocumented
Method ​_parse​_see​_also​_section Undocumented
Method ​_parse​_warns​_section Undocumented
Method ​_partition​_field​_on​_colon Undocumented
Method ​_partition​_multiline​_field​_on​_colon Partition multiple lines on colon. If the type or name span multiple lines, they will be automatically joined.
Method ​_strip​_empty Undocumented
Class Variable ​_name​_rgx Undocumented
Instance Variable ​_is​_attribute Undocumented
Instance Variable ​_is​_in​_section Undocumented
Instance Variable ​_line​_iter Undocumented
Instance Variable ​_parsed​_lines Undocumented
Instance Variable ​_process​_type​_fields Undocumented
Instance Variable ​_section​_indent Undocumented
Instance Variable ​_sections Undocumented
def __init__(self, docstring, is_attribute=False, process_type_fields=False):
Parameters
docstring:str or list of strThe docstring to parse, given either as a string or split into individual lines.
is​_attribute:boolIf the documented object is an attribute, it will use the _parse_attribute_docstring method.
process​_type​_fields:boolWhether to process the type fields or to leave them untouched (default) in order to be processed later. Value process_type_fields=False is currently only used in the tests.
def __str__(self):
Return the parsed docstring in reStructuredText format.
Returns
strUnicode version of the docstring.
def lines(self):
Return the parsed lines of the docstring in reStructuredText format.
Returns
list(str)The lines of the docstring in a list.
warnings: List[Tuple[str, int]] =
Warning messages triggered during the conversion.
def _consume_contiguous(self):

Undocumented

Returns
List[str]Undocumented
def _consume_empty(self):

Undocumented

Returns
List[str]Undocumented
def _consume_field(self, parse_type=True, prefer_type=False, **kwargs):

Undocumented

Parameters
parse​_type:boolUndocumented
prefer​_type:boolUndocumented
**kwargs:AnyUndocumented
Returns
FieldUndocumented
def _consume_fields(self, parse_type=True, prefer_type=False, multiple=False, **kwargs):

Undocumented

Parameters
parse​_type:boolUndocumented
prefer​_type:boolUndocumented
multiple:boolUndocumented
**kwargs:AnyUndocumented
Returns
List[Field]Undocumented
def _consume_indented_block(self, indent=1):

Undocumented

Parameters
indent:intUndocumented
Returns
List[str]Undocumented
def _consume_inline_attribute(self):

Undocumented

Returns
Tuple[str, List[str]]Undocumented
def _consume_returns_section(self):

Undocumented

Returns
List[Field]Undocumented
def _consume_section_header(self):

Undocumented

Returns
strUndocumented
def _consume_to_end(self):

Undocumented

Returns
List[str]Undocumented
def _consume_to_next_section(self):

Undocumented

Returns
List[str]Undocumented
def _convert_type(self, _type, is_type_field=True, lineno=0):
Tokenize the string type and convert it with additional markup and auto linking, with L{TypeDocstring}.
Parameters
​_type:boolthe string type to convert.
is​_type​_field:boolWhether the string is the content of a :type: or rtype field. If this is True and GoogleDocstring's process_type_fields is False (defaults), the type will NOT be converted (instead, it's returned as is) because it will be converted by the code provided by ParsedTypeDocstring class in a later stage of docstring parsing.
lineno:intUndocumented
Returns
strUndocumented
def _dedent(self, lines, full=False):

Undocumented

Parameters
lines:List[str]Undocumented
full:boolUndocumented
Returns
List[str]Undocumented
def _escape_args_and_kwargs(self, name):

Undocumented

Parameters
name:strUndocumented
Returns
strUndocumented
def _fix_field_desc(self, desc):

Undocumented

Parameters
desc:List[str]Undocumented
Returns
List[str]Undocumented
def _format_admonition(self, admonition, lines):

Undocumented

Parameters
admonition:strUndocumented
lines:List[str]Undocumented
Returns
List[str]Undocumented
def _format_block(self, prefix, lines, padding=''):

Undocumented

Parameters
prefix:strUndocumented
lines:List[str]Undocumented
padding:strUndocumented
Returns
List[str]Undocumented
def _format_docutils_params(self, fields, field_role='param', type_role='type'):

Undocumented

Parameters
fields:List[Field]Undocumented
field​_role:strUndocumented
type​_role:strUndocumented
Returns
List[str]Undocumented
def _format_field(self, _name, _type, _desc, lineno=0):

Undocumented

Parameters
​_name:strUndocumented
​_type:strUndocumented
​_desc:List[str]Undocumented
lineno:intUndocumented
Returns
List[str]Undocumented
def _format_fields(self, field_type, fields):

Undocumented

Parameters
field​_type:strUndocumented
fields:List[Field]Undocumented
Returns
List[str]Undocumented
def _get_current_indent(self, peek_ahead=0):

Undocumented

Parameters
peek​_ahead:intUndocumented
Returns
intUndocumented
def _get_indent(self, line):

Undocumented

Parameters
line:strUndocumented
Returns
intUndocumented
def _get_initial_indent(self, lines):

Undocumented

Parameters
lines:List[str]Undocumented
Returns
intUndocumented
def _get_min_indent(self, lines):

Undocumented

Parameters
lines:List[str]Undocumented
Returns
intUndocumented
def _indent(self, lines, n=4):

Undocumented

Parameters
lines:List[str]Undocumented
n:intUndocumented
Returns
List[str]Undocumented
def _is_indented(self, line, indent=1):

Undocumented

Parameters
line:strUndocumented
indent:intUndocumented
Returns
boolUndocumented
def _is_list(self, lines):

Undocumented

Parameters
lines:List[str]Undocumented
Returns
boolUndocumented
def _is_section_break(self):

Undocumented

Returns
boolUndocumented
def _is_section_header(self):

Undocumented

Returns
boolUndocumented
def _parse(self):

Undocumented

def _parse_admonition(self, admonition, section):

Undocumented

Parameters
admonition:strUndocumented
section:strUndocumented
Returns
List[str]Undocumented
def _parse_attribute_docstring(self):

Undocumented

Returns
List[str]Undocumented
def _parse_attributes_section(self, section):

Undocumented

Parameters
section:strUndocumented
Returns
List[str]Undocumented
def _parse_examples_section(self, section):

Undocumented

Parameters
section:strUndocumented
Returns
List[str]Undocumented
def _parse_generic_section(self, section):

Undocumented

Parameters
section:strUndocumented
Returns
List[str]Undocumented
def _parse_keyword_arguments_section(self, section):

Undocumented

Parameters
section:strUndocumented
Returns
List[str]Undocumented
def _parse_methods_section(self, section):

Undocumented

Parameters
section:strUndocumented
Returns
List[str]Undocumented
def _parse_notes_section(self, section):

Undocumented

Parameters
section:strUndocumented
Returns
List[str]Undocumented
def _parse_parameters_section(self, section):

Undocumented

Parameters
section:strUndocumented
Returns
List[str]Undocumented
def _parse_raises_section(self, section, field_type='raises', prefer_type=True):

Undocumented

Parameters
section:strUndocumented
field​_type:strUndocumented
prefer​_type:boolUndocumented
Returns
List[str]Undocumented
def _parse_references_section(self, section):

Undocumented

Parameters
section:strUndocumented
Returns
List[str]Undocumented
def _parse_returns_section(self, section):

Undocumented

Parameters
section:strUndocumented
Returns
List[str]Undocumented
def _parse_see_also_section(self, section):

Undocumented

Parameters
section:strUndocumented
Returns
List[str]Undocumented
def _parse_warns_section(self, section):

Undocumented

Parameters
section:strUndocumented
Returns
List[str]Undocumented
def _partition_field_on_colon(self, line):

Undocumented

Parameters
line:strUndocumented
Returns
Tuple[str, str, str]Undocumented
def _partition_multiline_field_on_colon(self, lines, format_validator):
Partition multiple lines on colon. If the type or name span multiple lines, they will be automatically joined.
Parameters
lines:List[str]Lines to split
format​_validator:Callable[[str], bool]

Validator returning bool indicates if the value of before_colon is sane. If the value is not sane, fall back to _partition_field_on_colon behaviour with a warning.

Note

The validator will be called with a one line string as the argument.

Note

Only used for multiline fields.

Returns
Tuple[str, str, List[str]]
  • before_colon: str - depending on the context this might be the first line of the description or the name with the optional type or the type.
  • colon: str
  • description: list(str) - Can contains lines with only white spaces.
def _strip_empty(self, lines):

Undocumented

Parameters
lines:List[str]Undocumented
Returns
List[str]Undocumented
_name_rgx =

Undocumented

_is_attribute =

Undocumented

_is_in_section: bool =

Undocumented

_line_iter: modify_iter[str] =

Undocumented

_parsed_lines =

Undocumented

_process_type_fields =

Undocumented

_section_indent: int =

Undocumented

_sections: Dict[str, Callable[[str], List[str]]] =

Undocumented