class documentation

class StubGenerator(mypy.traverser.TraverserVisitor): (source)

View In Hierarchy

Generate stub text from a mypy AST.
Method __init__ Undocumented
Method add Add text to generated stub.
Method add​_abc​_import Add a name to be imported from collections.abc, unless it's imported already.
Method add​_coroutine​_decorator Undocumented
Method add​_decorator Undocumented
Method add​_import​_line Add a line of text to the import section, unless it's already there.
Method add​_typing​_import Add a name to be imported from typing, unless it's imported already.
Method clear​_decorators Undocumented
Method get​_base​_types Get list of base classes for a class.
Method get​_init Return initializer for a variable.
Method get​_str​_type​_of​_node Undocumented
Method is​_alias​_expression Return True for things that look like target for an alias.
Method is​_namedtuple Undocumented
Method is​_none​_expr Undocumented
Method is​_not​_in​_all Undocumented
Method is​_private​_member Undocumented
Method is​_private​_name Undocumented
Method is​_recorded​_name Has this name been recorded previously?
Method is​_top​_level Are we processing the top level of a file?
Method output Return the text for the stub.
Method print​_annotation Undocumented
Method process​_decorator Process a series of decorators.
Method process​_member​_expr​_decorator Process a function decorator of form @foo.bar.
Method process​_name​_expr​_decorator Process a function decorator of form @foo.
Method process​_namedtuple Undocumented
Method process​_typealias Undocumented
Method record​_name Mark a name as defined.
Method refers​_to​_fullname Undocumented
Method typing​_name Undocumented
Method visit​_assignment​_stmt Undocumented
Method visit​_block Undocumented
Method visit​_class​_def Undocumented
Method visit​_decorator Undocumented
Method visit​_func​_def Undocumented
Method visit​_if​_stmt Undocumented
Method visit​_import Undocumented
Method visit​_import​_all Undocumented
Method visit​_import​_from Undocumented
Method visit​_mypy​_file Undocumented
Method visit​_overloaded​_func​_def @property with setters and getters, or @overload chain
Instance Variable analyzed Undocumented
Instance Variable defined​_names Undocumented
Instance Variable export​_less Undocumented
Instance Variable import​_tracker Undocumented
Instance Variable method​_names Undocumented
Instance Variable module Undocumented
Instance Variable path Undocumented
Instance Variable referenced​_names Undocumented
Instance Variable _all_ Undocumented
Instance Variable _decorators Undocumented
Instance Variable _import​_lines Undocumented
Instance Variable _include​_private Undocumented
Instance Variable _indent Undocumented
Instance Variable _output Undocumented
Instance Variable _pyversion Undocumented
Instance Variable _state Undocumented
Instance Variable _toplevel​_names Undocumented
Instance Variable _vars Undocumented

Inherited from TraverserVisitor:

Method visit​_assert​_stmt Undocumented
Method visit​_assignment​_expr Undocumented
Method visit​_await​_expr Undocumented
Method visit​_backquote​_expr Undocumented
Method visit​_call​_expr Undocumented
Method visit​_cast​_expr Undocumented
Method visit​_comparison​_expr Undocumented
Method visit​_conditional​_expr Undocumented
Method visit​_del​_stmt Undocumented
Method visit​_dict​_expr Undocumented
Method visit​_dictionary​_comprehension Undocumented
Method visit​_exec​_stmt Undocumented
Method visit​_expression​_stmt Undocumented
Method visit​_for​_stmt Undocumented
Method visit​_func Undocumented
Method visit​_generator​_expr Undocumented
Method visit​_index​_expr Undocumented
Method visit​_lambda​_expr Undocumented
Method visit​_list​_comprehension Undocumented
Method visit​_list​_expr Undocumented
Method visit​_member​_expr Undocumented
Method visit​_op​_expr Undocumented
Method visit​_operator​_assignment​_stmt Undocumented
Method visit​_print​_stmt Undocumented
Method visit​_raise​_stmt Undocumented
Method visit​_return​_stmt Undocumented
Method visit​_reveal​_expr Undocumented
Method visit​_set​_comprehension Undocumented
Method visit​_set​_expr Undocumented
Method visit​_slice​_expr Undocumented
Method visit​_star​_expr Undocumented
Method visit​_super​_expr Undocumented
Method visit​_try​_stmt Undocumented
Method visit​_tuple​_expr Undocumented
Method visit​_type​_application Undocumented
Method visit​_unary​_expr Undocumented
Method visit​_while​_stmt Undocumented
Method visit​_with​_stmt Undocumented
Method visit​_yield​_expr Undocumented
Method visit​_yield​_from​_expr Undocumented
def __init__(self, _all_, pyversion, include_private=False, analyzed=False, export_less=False): (source)

Undocumented

Parameters
_all_:Optional[List[str]]Undocumented
pyversion:Tuple[int, int]Undocumented
include​_private:boolUndocumented
analyzed:boolUndocumented
export​_less:boolUndocumented
def add(self, string): (source)
Add text to generated stub.
Parameters
string:strUndocumented
def add_abc_import(self, name): (source)

Add a name to be imported from collections.abc, unless it's imported already.

The import will be internal to the stub.

Parameters
name:strUndocumented
def add_coroutine_decorator(self, func, name, require_name): (source)

Undocumented

Parameters
func:FuncDefUndocumented
name:strUndocumented
require​_name:strUndocumented
def add_decorator(self, name): (source)

Undocumented

Parameters
name:strUndocumented
def add_import_line(self, line): (source)
Add a line of text to the import section, unless it's already there.
Parameters
line:strUndocumented
def add_typing_import(self, name): (source)

Add a name to be imported from typing, unless it's imported already.

The import will be internal to the stub.

Parameters
name:strUndocumented
def clear_decorators(self): (source)

Undocumented

def get_base_types(self, cdef): (source)
Get list of base classes for a class.
Parameters
cdef:ClassDefUndocumented
Returns
List[str]Undocumented
def get_init(self, lvalue, rvalue, annotation=None): (source)

Return initializer for a variable.

Return None if we've generated one already or if the variable is internal.

Parameters
lvalue:strUndocumented
rvalue:ExpressionUndocumented
annotation:Optional[Type]Undocumented
Returns
Optional[str]Undocumented
def get_str_type_of_node(self, rvalue, can_infer_optional=False, can_be_any=True): (source)

Undocumented

Parameters
rvalue:ExpressionUndocumented
can​_infer​_optional:boolUndocumented
can​_be​_any:boolUndocumented
Returns
strUndocumented
def is_alias_expression(self, expr, top_level=True): (source)

Return True for things that look like target for an alias.

Used to know if assignments look like type aliases, function alias, or module alias.

Parameters
expr:ExpressionUndocumented
top​_level:boolUndocumented
Returns
boolUndocumented
def is_namedtuple(self, expr): (source)

Undocumented

Parameters
expr:ExpressionUndocumented
Returns
boolUndocumented
def is_none_expr(self, expr): (source)

Undocumented

Parameters
expr:ExpressionUndocumented
Returns
boolUndocumented
def is_not_in_all(self, name): (source)

Undocumented

Parameters
name:strUndocumented
Returns
boolUndocumented
def is_private_member(self, fullname): (source)

Undocumented

Parameters
fullname:strUndocumented
Returns
boolUndocumented
def is_private_name(self, name, fullname=None): (source)

Undocumented

Parameters
name:strUndocumented
fullname:Optional[str]Undocumented
Returns
boolUndocumented
def is_recorded_name(self, name): (source)
Has this name been recorded previously?
Parameters
name:strUndocumented
Returns
boolUndocumented
def is_top_level(self): (source)
Are we processing the top level of a file?
Returns
boolUndocumented
def output(self): (source)
Return the text for the stub.
Returns
strUndocumented
def print_annotation(self, t): (source)

Undocumented

Parameters
t:TypeUndocumented
Returns
strUndocumented
def process_decorator(self, o): (source)

Process a series of decorators.

Only preserve certain special decorators such as @abstractmethod.

Return a pair of booleans: - True if any of the decorators makes a method abstract. - True if any of the decorators is typing.overload.

Parameters
o:DecoratorUndocumented
Returns
Tuple[bool, bool]Undocumented
def process_member_expr_decorator(self, expr, context): (source)

Process a function decorator of form @foo.bar.

Only preserve certain special decorators such as @abstractmethod.

Return a pair of booleans: - True if the decorator makes a method abstract. - True if the decorator is typing.overload.

Parameters
expr:MemberExprUndocumented
context:DecoratorUndocumented
Returns
Tuple[bool, bool]Undocumented
def process_name_expr_decorator(self, expr, context): (source)

Process a function decorator of form @foo.

Only preserve certain special decorators such as @abstractmethod.

Return a pair of booleans: - True if the decorator makes a method abstract. - True if the decorator is typing.overload.

Parameters
expr:NameExprUndocumented
context:DecoratorUndocumented
Returns
Tuple[bool, bool]Undocumented
def process_namedtuple(self, lvalue, rvalue): (source)

Undocumented

Parameters
lvalue:NameExprUndocumented
rvalue:CallExprUndocumented
def process_typealias(self, lvalue, rvalue): (source)

Undocumented

Parameters
lvalue:NameExprUndocumented
rvalue:ExpressionUndocumented
def record_name(self, name): (source)

Mark a name as defined.

This only does anything if at the top level of a module.

Parameters
name:strUndocumented
def refers_to_fullname(self, name, fullname): (source)

Undocumented

Parameters
name:strUndocumented
fullname:strUndocumented
Returns
boolUndocumented
def typing_name(self, name): (source)

Undocumented

Parameters
name:strUndocumented
Returns
strUndocumented
def visit_assignment_stmt(self, o): (source)

Undocumented

Parameters
o:AssignmentStmtUndocumented
def visit_block(self, o): (source)

Undocumented

Parameters
o:BlockUndocumented
def visit_class_def(self, o): (source)

Undocumented

Parameters
o:ClassDefUndocumented
def visit_decorator(self, o): (source)

Undocumented

Parameters
o:DecoratorUndocumented
def visit_func_def(self, o, is_abstract=False, is_overload=False): (source)

Undocumented

Parameters
o:FuncDefUndocumented
is​_abstract:boolUndocumented
is​_overload:boolUndocumented
def visit_if_stmt(self, o): (source)

Undocumented

Parameters
o:IfStmtUndocumented
def visit_import(self, o): (source)

Undocumented

Parameters
o:ImportUndocumented
def visit_import_all(self, o): (source)

Undocumented

Parameters
o:ImportAllUndocumented
def visit_import_from(self, o): (source)

Undocumented

Parameters
o:ImportFromUndocumented
def visit_mypy_file(self, o): (source)

Undocumented

Parameters
o:MypyFileUndocumented
def visit_overloaded_func_def(self, o): (source)
@property with setters and getters, or @overload chain
Parameters
o:OverloadedFuncDefUndocumented
analyzed = (source)

Undocumented

defined_names = (source)

Undocumented

export_less = (source)

Undocumented

import_tracker = (source)

Undocumented

method_names = (source)

Undocumented

module = (source)

Undocumented

path = (source)

Undocumented

referenced_names = (source)

Undocumented

_all_ = (source)

Undocumented

_decorators: List[str] = (source)

Undocumented

_import_lines: List[str] = (source)

Undocumented

_include_private = (source)

Undocumented

_indent = (source)

Undocumented

_output: List[str] = (source)

Undocumented

_pyversion = (source)

Undocumented

_state = (source)

Undocumented

_toplevel_names: List[str] = (source)

Undocumented

_vars: List[List[str]] = (source)

Undocumented