stubber.rst

.rst processing

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

TYPING_IMPORT

LOOKUP_LIST

NONE_VERBS

CHILD_PARENT_CLASS

PARAM_FIXES

MODULE_GLUE

RST_DOC_FIXES

DOCSTUB_SKIP

this is an list with manual overrides for function returns that could not efficiently be determined

U_MODULES

List of modules that are documented with the base name only,

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.TYPING_IMPORT: List[str] = ['from __future__ import annotations', 'from typing import IO, Any, Callable, Coroutine, Dict,...
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
stubber.rst.MODULE_GLUE
stubber.rst.RST_DOC_FIXES: List[Tuple[str, str]] = [(':class: attention\n', ''), ('.. method:: match.', '.. method:: Match.'), ('           ...
stubber.rst.DOCSTUB_SKIP = ['uasyncio.rst', 'builtins.rst', 're.rst']

this is an list with manual overrides for function returns that could not efficiently be determined from their docstring description Format: a dictionary with : - key = module.[class.]function name - value : two-tuple with ( return type , priority )

stubber.rst.U_MODULES = ['array', 'binascii', 'io', 'json', 'os', 'select', 'ssl', 'struct', 'socket', 'time', 'zlib']

List of modules that are documented with the base name only, but can also be imported with a u prefix

class stubber.rst.SourceDict(base: List, indent: int = 0, body: int = 0, lf: str = '\n', name='')

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 ( the to be generated source code )

Return type:

str

__add__(other: SourceDict)

Aallows instances of the SourceDict class to be added together using the + operator or the += operator.

Parameters:

other (SourceDict) –

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

  • extra (int) –

add_comment(line: 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 = '', docstr: List[str] | None = None, 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 (Optional[List[str]]) –

  • autoindent (bool) –

abstract find(name: str) 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__()

sort in the correct parent-child order, then convert to string (the code)

find(name: str) 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: 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] | None = None, 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 (Optional[List[str]]) –

  • init (str) –

  • indent (int) –

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

Bases: SourceDict

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

Parameters:
  • name (str) –

  • definition (Optional[List[str]]) –

  • docstr (Optional[List[str]]) –

  • indent (int) –

  • decorators (Optional[List[str]]) –

  • is_async (bool) –

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

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 (Optional[List[str]]) –

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

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 (Optional[List[str]]) –

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

find and rate possible types and confidence weighting for Object types. Case sensitive Exclude defaults to [“IRQ”]

Parameters:
  • match_string (str) –

  • rate (float) –

  • exclude (Optional[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: 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: 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 __future__ import annotations', 'from typing import IO, Any, Callable, Coroutine, Dict,...
stubber.rst.__all__