module documentation
(source)

Parsing/inferring signatures from documentation.

This module provides several functions to generate better stubs using docstrings and Sphinx docs (.rst files).

Class ​Arg​Sig Signature info for a single argument.
Class ​Doc​String​Parser Parse function signatures in documentation.
Function build​_signature Build function signature from lists of positional and optional argument names.
Function find​_unique​_signatures Remove names with duplicate found signatures.
Function infer​_arg​_sig​_from​_anon​_docstring Convert signature in form of "(self: TestClass, arg0: str='ada')" to List[TypedArgList].
Function infer​_prop​_type​_from​_docstring Check for Google/Numpy style docstring type annotation for a property.
Function infer​_ret​_type​_sig​_from​_anon​_docstring Convert signature in form of "(self: TestClass, arg0) -> int" to their return type.
Function infer​_ret​_type​_sig​_from​_docstring Convert signature in form of "func(self: TestClass, arg0) -> int" to their return type.
Function infer​_sig​_from​_docstring Convert function signature to list of TypedFunctionSig
Function is​_valid​_type Try to determine whether a string might be a valid type annotation.
Function parse​_all​_signatures Parse all signatures in a given reST document.
Function parse​_signature Split function signature into its name, positional an optional arguments.
Constant STATE​_ARGUMENT​_DEFAULT Undocumented
Constant STATE​_ARGUMENT​_LIST Undocumented
Constant STATE​_ARGUMENT​_TYPE Undocumented
Constant STATE​_FUNCTION​_NAME Undocumented
Constant STATE​_INIT Undocumented
Constant STATE​_OPEN​_BRACKET Undocumented
Constant STATE​_RETURN​_VALUE Undocumented
Variable ​Function​Sig Undocumented
Variable ​Sig Undocumented
Constant _ARG​_NAME​_RE Undocumented
Constant _TYPE​_RE Undocumented
def build_signature(positional, optional): (source)
Build function signature from lists of positional and optional argument names.
Parameters
positional:Sequence[str]Undocumented
optional:Sequence[str]Undocumented
Returns
strUndocumented
def find_unique_signatures(sigs): (source)
Remove names with duplicate found signatures.
Parameters
sigs:Sequence[Sig]Undocumented
Returns
List[Sig]Undocumented
def infer_arg_sig_from_anon_docstring(docstr): (source)
Convert signature in form of "(self: TestClass, arg0: str='ada')" to List[TypedArgList].
Parameters
docstr:strUndocumented
Returns
List[ArgSig]Undocumented
def infer_prop_type_from_docstring(docstr): (source)

Check for Google/Numpy style docstring type annotation for a property.

The docstring has the format "<type>: <descriptions>". In the type string, we allow the following characters: * dot: because sometimes classes are annotated using full path * brackets: to allow type hints like List[int] * comma/space: things like Tuple[int, int]

Parameters
docstr:Optional[str]Undocumented
Returns
Optional[str]Undocumented
def infer_ret_type_sig_from_anon_docstring(docstr): (source)
Convert signature in form of "(self: TestClass, arg0) -> int" to their return type.
Parameters
docstr:strUndocumented
Returns
Optional[str]Undocumented
def infer_ret_type_sig_from_docstring(docstr, name): (source)
Convert signature in form of "func(self: TestClass, arg0) -> int" to their return type.
Parameters
docstr:strUndocumented
name:strUndocumented
Returns
Optional[str]Undocumented
def infer_sig_from_docstring(docstr, name): (source)

Convert function signature to list of TypedFunctionSig

Look for function signatures of function in docstring. Signature is a string of the format <function_name>(<signature>) -> <return type> or perhaps without the return type.

Returns empty list, when no signature is found, one signature in typical case, multiple signatures, if docstring specifies multiple signatures for overload functions. Return None if the docstring is empty.

Arguments:
  • docstr: docstring
  • name: name of function for which signatures are to be found
Parameters
docstr:Optional[str]Undocumented
name:strUndocumented
Returns
Optional[List[FunctionSig]]Undocumented
def is_valid_type(s): (source)
Try to determine whether a string might be a valid type annotation.
Parameters
s:strUndocumented
Returns
boolUndocumented
def parse_all_signatures(lines): (source)

Parse all signatures in a given reST document.

Return lists of found signatures for functions and classes.

Parameters
lines:Sequence[str]Undocumented
Returns
Tuple[List[Sig], List[Sig]]Undocumented
def parse_signature(sig): (source)

Split function signature into its name, positional an optional arguments.

The expected format is "func_name(arg, opt_arg=False)". Return the name of function and lists of positional and optional argument names.

Parameters
sig:strUndocumented
Returns
Optional[Tuple[str, List[str], List[str]]]Undocumented
STATE_ARGUMENT_DEFAULT: int = (source)

Undocumented

Value
5
STATE_ARGUMENT_LIST: int = (source)

Undocumented

Value
3
STATE_ARGUMENT_TYPE: int = (source)

Undocumented

Value
4
STATE_FUNCTION_NAME: int = (source)

Undocumented

Value
2
STATE_INIT: int = (source)

Undocumented

Value
1
STATE_OPEN_BRACKET: int = (source)

Undocumented

Value
7
STATE_RETURN_VALUE: int = (source)

Undocumented

Value
6
FunctionSig = (source)

Undocumented

Undocumented

_ARG_NAME_RE = (source)

Undocumented

Value
re.compile(r'\**[A-Za-z_][A-Za-z0-9_]*$')
_TYPE_RE = (source)

Undocumented

Value
re.compile(r'^[a-zA-Z_][\w\[\], ]*(\.[a-zA-Z_][\w\[\], ]*)*$')