stubber.rst.output_dict

ModuleSourceDict represents a source file with the following components
  • docstr

  • version

  • comment

  • typing

  • Optional: list of constants

  • optional: ClassSourcedicts

  • optional: FunctionSourcedicts

  • optional: individual lines of code

ClassSourceDict represents a source file with the following components
  • comment

  • class

  • docstr

  • Optional: list of constants

  • __init__ : class signature

  • optional: FunctionSourcedicts

  • optional: individual lines of code

FunctionSourceDict represents a source file with the following components
  • # comments - todo

  • optional: decorator

  • def - function definition

  • docstr

  • constants

  • body - …

  • optional: individual lines of code

SourceDict is the ‘base class’

Module 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

class stubber.rst.output_dict.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.output_dict.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.output_dict.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.output_dict.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) –