stubber.rst

Submodules

Package Contents

Classes

SourceDict

(abstract) dict to store source components respecting parent child dependencies and proper definition order

ModuleSourceDict

(abstract) dict to store source components respecting parent child dependencies and proper definition order

ClassSourceDict

(abstract) dict to store source components respecting parent child dependencies and proper definition order

FunctionSourceDict

(abstract) dict to store source components respecting parent child dependencies and proper definition order

Functions

sort_classes(classes)

sort a list of classes to respect the parent-child order

simple_candidates(type, match_string, keywords[, ...])

find and rate possible types and confidence weighting for simple types.

compound_candidates(type, match_string, keywords[, ...])

find and rate possible types and confidence weighting for compound types that can have a subscription.

object_candidates(match_string[, rate, exclude])

find and rate possible types and confidence weighting for Object types.

distill_return(→ List[Dict])

Find return type and confidence.

return_type_from_context(*, docstring, signature, module)

_type_from_context(*, docstring, signature, module[, ...])

Determine the return type of a function or method based on:

Attributes

LOOKUP_LIST

NONE_VERBS

CHILD_PARENT_CLASS

PARAM_FIXES

MODULE_GLUE

RST_DOC_FIXES

DOCSTUB_SKIP

U_MODULES

TYPING_IMPORT

__all__

stubber.rst.sort_classes(classes: List[str])

sort a list of classes to respect the parent-child order

Parameters

classes (List[str]) –

stubber.rst.LOOKUP_LIST
stubber.rst.NONE_VERBS = ['Activate ', 'Build a ', 'Cancel ', 'Clear ', 'Close ', 'cancel ', 'Configure ', 'Connect ',...
stubber.rst.CHILD_PARENT_CLASS
stubber.rst.PARAM_FIXES = [['\\*', '*'], ['\\**', '*'], ['/*', '*'], ["'param'", 'param'], ['lambda', 'lambda_fn'],...
stubber.rst.MODULE_GLUE
stubber.rst.RST_DOC_FIXES = [['.. method:: match.', '.. method:: Match.'], ['            match.end', '           ...
stubber.rst.DOCSTUB_SKIP = ['uasyncio.rst', 'builtins.rst', 're.rst']
stubber.rst.U_MODULES = ['os', 'time', 'array', 'binascii', 'io', 'json', 'select', 'socket', 'ssl', 'struct', 'zlib']
class stubber.rst.SourceDict(base: List, indent: int = 0, body: int = 0, lf: str = '\n')

Bases: OrderedDict

(abstract) dict to store source components respecting parent child dependencies and proper definition order

Parameters
  • base (List) –

  • indent (int) –

  • body (int) –

  • lf (str) –

__str__() str

convert the OD into a string

Return type

str

__add__(dict: SourceDict)
Parameters

dict (SourceDict) –

add_docstr(docstr: Union[str, List[str]], extra: int = 0)
Parameters
  • docstr (Union[str, List[str]]) –

  • extra (int) –

add_comment(line: Union[str, List[str]])

Add a comment, or list of comments, to this block.

Parameters

line (Union[str, List[str]]) –

add_constant(line: str, autoindent: bool = True)

add constant to the constant scope of this block

Parameters
  • line (str) –

  • autoindent (bool) –

add_constant_smart(name: str, type: str = 'Any', docstr: List[str] = [], autoindent: bool = True)

add literal / constant to the constant scope of this block, or a class in this block

Parameters
  • name (str) –

  • type (str) –

  • docstr (List[str]) –

  • autoindent (bool) –

abstract find(name: str) Union[str, None]
Parameters

name (str) –

Return type

Union[str, None]

add_line(line: str, autoindent: bool = True)
Parameters
  • line (str) –

  • autoindent (bool) –

index(key: str)
Parameters

key (str) –

class stubber.rst.ModuleSourceDict(name: str, indent=0, lf: str = '\n')

Bases: SourceDict

(abstract) dict to store source components respecting parent child dependencies and proper definition order

Parameters
sort()

make sure all classdefs are in order

__str__()

convert the OD into a string

find(name: str) Union[str, None]

find a classnode based on the name with or without the superclass

Parameters

name (str) –

Return type

Union[str, None]

classes()

get a list of the class names in parent-child order

add_import(imports: Union[str, List[str]])

add a [list of] imports this module

Parameters

imports (Union[str, List[str]]) –

class stubber.rst.ClassSourceDict(name: str, *, docstr: List[str] = ['""" """'], init: str = '', indent: int = 0, lf='\n')

Bases: SourceDict

(abstract) dict to store source components respecting parent child dependencies and proper definition order

Parameters
  • name (str) –

  • docstr (List[str]) –

  • init (str) –

  • indent (int) –

class stubber.rst.FunctionSourceDict(name: str, *, definition: List[str] = [], docstr: List[str] = ['""" """'], indent: int = 0, decorators: List[str] = [], lf='\n')

Bases: SourceDict

(abstract) dict to store source components respecting parent child dependencies and proper definition order

Parameters
  • name (str) –

  • definition (List[str]) –

  • docstr (List[str]) –

  • indent (int) –

  • decorators (List[str]) –

stubber.rst.simple_candidates(type: str, match_string: str, keywords: List[str], rate: float = 0.5, exclude: List[str] = [])

find and rate possible types and confidence weighting for simple types. Case sensitive

Parameters
  • type (str) –

  • match_string (str) –

  • keywords (List[str]) –

  • rate (float) –

  • exclude (List[str]) –

stubber.rst.compound_candidates(type: str, match_string: str, keywords: List[str], rate: float = 0.85, exclude: List[str] = [])

find and rate possible types and confidence weighting for compound types that can have a subscription. Case sensitive

Parameters
  • type (str) –

  • match_string (str) –

  • keywords (List[str]) –

  • rate (float) –

  • exclude (List[str]) –

stubber.rst.object_candidates(match_string: str, rate: float = 0.81, exclude: List[str] = ['IRQ'])

find and rate possible types and confidence weighting for Object types. Case sensitive

Parameters
  • match_string (str) –

  • rate (float) –

  • exclude (List[str]) –

stubber.rst.distill_return(return_text: str) List[Dict]

Find return type and confidence. Returns a list of possible types and confidence weighting. {

type :str # the return type confidence: float # the confidence between 0.0 and 1 match: Optional[str] # for debugging : the reason the match was made

}

Parameters

return_text (str) –

Return type

List[Dict]

stubber.rst.return_type_from_context(*, docstring: Union[str, List[str]], signature: str, module: str, literal: bool = False)
Parameters
  • docstring (Union[str, List[str]]) –

  • signature (str) –

  • module (str) –

  • literal (bool) –

stubber.rst._type_from_context(*, docstring: Union[str, List[str]], signature: str, module: str, literal: bool = False)
Determine the return type of a function or method based on:
  • the function signature

  • the terminology used in the docstring

Logic: - if the signature contains a return type –> <something> then that is returned - use re to find phrases such as:

  • ‘Returns ….. ‘

  • ‘Gets ….. ‘

  • docstring is joined without newlines to simplify parsing

  • then parses the docstring to find references to known types and give then a rating though a hand coded model ()

  • builds a list return type candidates

  • selects the highest ranking candidate

  • the default Type is ‘Any’

Parameters
  • docstring (Union[str, List[str]]) –

  • signature (str) –

  • module (str) –

  • literal (bool) –

stubber.rst.TYPING_IMPORT :List[str] = ['from typing import IO, Any, Callable, Coroutine, Dict, Generator, Iterator, List, NoReturn,...
stubber.rst.__all__