stubber.cst_transformer

Module Contents

Classes

TypeInfo

contains the functiondefs and classdefs info read from the stubs source

StubTypingCollector

The low-level base visitor class for traversing a CST. This should be used in

Functions

update_def_docstr(→ Any)

Update the docstring of a function/method or class

update_module_docstr(→ Any)

Update the docstring of a module

Attributes

MODULE_KEY

_m

class stubber.cst_transformer.TypeInfo

contains the functiondefs and classdefs info read from the stubs source

name :str
decorators :Sequence[libcst.Decorator]
params :Optional[libcst.Parameters]
returns :Optional[libcst.Annotation]
docstr_node :Optional[libcst.SimpleStatementLine]
def_node :Optional[Union[libcst.FunctionDef, libcst.ClassDef]]
def_type :str = ?
exception stubber.cst_transformer.TransformError

Bases: Exception

Error raised upon encountering a known error while attempting to transform the tree.

stubber.cst_transformer.MODULE_KEY
stubber.cst_transformer._m
class stubber.cst_transformer.StubTypingCollector

Bases: libcst.CSTVisitor

The low-level base visitor class for traversing a CST. This should be used in conjunction with the visit() method on a CSTNode to visit each element in a tree starting with that node. Unlike CSTTransformer, instances of this class cannot modify the tree.

When visiting nodes using a CSTVisitor, the return value of visit() will equal the passed in tree.

visit_Module(node: libcst.Module) bool

Store the module docstring

Parameters

node (libcst.Module) –

Return type

bool

visit_ClassDef(node: libcst.ClassDef) Optional[bool]

Store the class docstring

Parameters

node (libcst.ClassDef) –

Return type

Optional[bool]

leave_ClassDef(original_node: libcst.ClassDef) None
Parameters

original_node (libcst.ClassDef) –

Return type

None

visit_FunctionDef(node: libcst.FunctionDef) Optional[bool]

store each function/method signature

Parameters

node (libcst.FunctionDef) –

Return type

Optional[bool]

leave_FunctionDef(original_node: libcst.FunctionDef) None
Parameters

original_node (libcst.FunctionDef) –

Return type

None

stubber.cst_transformer.update_def_docstr(dest_node: Union[libcst.FunctionDef, libcst.ClassDef], src_comment: Optional[libcst.SimpleStatementLine], src_node=None) Any

Update the docstring of a function/method or class

for functiondefs ending in an ellipsis, the entire body needs to be replaced. in this case the src_body is mandatory.

Parameters
  • dest_node (Union[libcst.FunctionDef, libcst.ClassDef]) –

  • src_comment (Optional[libcst.SimpleStatementLine]) –

Return type

Any

stubber.cst_transformer.update_module_docstr(node: libcst.Module, doc_tree: Optional[libcst.SimpleStatementLine]) Any

Update the docstring of a module

Parameters
  • node (libcst.Module) –

  • doc_tree (Optional[libcst.SimpleStatementLine]) –

Return type

Any