stubber.typing_collector¶
helper functions for stub transformations
Attributes¶
Exceptions¶
Error raised upon encountering a known error while attempting to transform |
Classes¶
contains the functionDefs and classDefs info read from the stubs source |
|
The different values for the annotations |
|
Collect the function/method and class definitions from ta rich .py or .pyi source |
Functions¶
|
check if the function is a property |
|
check if the function is a setter |
|
check if the function is a getter |
|
check if the function is a deleter |
|
Update the docstring of a function/method or class |
|
Add or update the docstring of a module |
Module Contents¶
- class stubber.typing_collector.TypeInfo¶
contains the functionDefs and classDefs info read from the stubs source
- decorators: Sequence[libcst.Decorator]¶
- class stubber.typing_collector.AnnoValue¶
The different values for the annotations
- exception stubber.typing_collector.TransformError¶
Bases:
ExceptionError raised upon encountering a known error while attempting to transform the tree.
- stubber.typing_collector.MODULE_KEY = ('__module',)¶
- stubber.typing_collector.MOD_DOCSTR_KEY = ('__module_docstring',)¶
- stubber.typing_collector._code¶
- stubber.typing_collector.is_property(node: libcst.FunctionDef) bool¶
check if the function is a property
- Parameters:
node (libcst.FunctionDef)
- Return type:
- stubber.typing_collector.is_setter(node: libcst.FunctionDef) bool¶
check if the function is a setter
- Parameters:
node (libcst.FunctionDef)
- Return type:
- stubber.typing_collector.is_getter(node: libcst.FunctionDef) bool¶
check if the function is a getter
- Parameters:
node (libcst.FunctionDef)
- Return type:
- stubber.typing_collector.is_deleter(node: libcst.FunctionDef) bool¶
check if the function is a deleter
- Parameters:
node (libcst.FunctionDef)
- Return type:
- class stubber.typing_collector.StubTypingCollector¶
Bases:
libcst.CSTVisitorCollect the function/method and class definitions from ta rich .py or .pyi source
- _collect_literal_docstrings(body: Sequence[libcst.BaseStatement]) Dict[str, libcst.SimpleStatementLine]¶
Collect literal docstrings from a sequence of statements. Looks for patterns like: CONSTANT = value ‘’’docstring for constant’’’
- Parameters:
body (Sequence[libcst.BaseStatement])
- Return type:
Dict[str, libcst.SimpleStatementLine]
- visit_Module(node: libcst.Module) bool¶
Store the module docstring and collect literal docstrings
- 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 - class-level literal docstrings
- 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.typing_collector.update_def_docstr(dest_node: libcst.FunctionDef | libcst.ClassDef, src_docstr: libcst.SimpleStatementLine | str | None = None, src_node=None) Any¶
Update the docstring of a function/method or class The supplied src_docstr can be a string or a SimpleStatementLine
for function defs ending in an ellipsis, the entire body needs to be replaced. in this case src_node is required.
- Parameters:
dest_node (Union[libcst.FunctionDef, libcst.ClassDef])
src_docstr (Optional[Union[libcst.SimpleStatementLine, str]])
- Return type:
Any
- stubber.typing_collector.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