stubber.cst_transformer
¶
helper functions for stub transformations
Module Contents¶
Classes¶
contains the functiondefs and classdefs info read from the stubs source |
|
Collect the function/method and class definitions from the stubs source |
Functions¶
|
Update the docstring of a function/method or class |
|
Add or update the docstring of a module |
Attributes¶
- class stubber.cst_transformer.TypeInfo¶
contains the functiondefs and classdefs info read from the stubs source
- decorators: Sequence[libcst.Decorator]¶
- 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 = ('__module',)¶
- stubber.cst_transformer.MODDOC_KEY = ('__module_docstring',)¶
- stubber.cst_transformer._m¶
- class stubber.cst_transformer.StubTypingCollector¶
Bases:
libcst.CSTVisitor
Collect the function/method and class definitions from the stubs source
- visit_Module(node: libcst.Module) bool ¶
Store the module docstring
- Parameters:
node (libcst.Module) –
- Return type:
- visit_Comment(node: libcst.Comment) None ¶
connect comments from the source
- Parameters:
node (libcst.Comment) –
- Return type:
None
- visit_ClassDef(node: libcst.ClassDef) bool | None ¶
collect info from a classdef: - name, decorators, docstring
- Parameters:
node (libcst.ClassDef) –
- Return type:
Optional[bool]
- leave_ClassDef(original_node: libcst.ClassDef) None ¶
remove the class name from the stack
- Parameters:
original_node (libcst.ClassDef) –
- Return type:
None
- visit_FunctionDef(node: libcst.FunctionDef) bool | None ¶
collect info from a function/method - name, decorators, params, returns, docstring
- Parameters:
node (libcst.FunctionDef) –
- Return type:
Optional[bool]
- update_append_first_node(node)¶
Store the function/method docstring or function/method sig
- stubber.cst_transformer.update_def_docstr(dest_node: libcst.FunctionDef | libcst.ClassDef, src_comment: libcst.SimpleStatementLine | None, 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: str | libcst.SimpleStatementLine | libcst.BaseCompoundStatement | None) Any ¶
Add or update the docstring of a module
- Parameters:
node (libcst.Module) –
doc_tree (Optional[Union[str, libcst.SimpleStatementLine, libcst.BaseCompoundStatement]]) –
- Return type:
Any