def find_self_initializers(fdef: FuncBase) -> List[Tuple[str, Expression]]: """Find attribute initializers in a method. Return a list of pairs (attribute name, r.h.s. expression). """ traverser = SelfTraverser() fdef.accept(traverser) return traverser.results
def has_return_statement(fdef: FuncBase) -> bool: """Find if a function has a non-trivial return statement. Plain 'return' and 'return None' don't count. """ seeker = ReturnSeeker() fdef.accept(seeker) return seeker.found
def has_return_statement(fdef: FuncBase) -> bool: class ReturnSeeker(mypy.traverser.TraverserVisitor): def __init__(self) -> None: self.found = False def visit_return_stmt(self, o: ReturnStmt) -> None: self.found = True seeker = ReturnSeeker() fdef.accept(seeker) return seeker.found
def find_self_initializers(fdef: FuncBase) -> List[Tuple[str, Expression]]: results = [] # type: List[Tuple[str, Expression]] class SelfTraverser(mypy.traverser.TraverserVisitor): def visit_assignment_stmt(self, o: AssignmentStmt) -> None: lvalue = o.lvalues[0] if (isinstance(lvalue, MemberExpr) and isinstance(lvalue.expr, NameExpr) and lvalue.expr.name == 'self'): results.append((lvalue.name, o.rvalue)) fdef.accept(SelfTraverser()) return results
def find_self_initializers(fdef: FuncBase) -> List[str]: results = [] # type: List[str] class SelfTraverser(mypy.traverser.TraverserVisitor): def visit_assignment_stmt(self, o: AssignmentStmt) -> None: lvalue = o.lvalues[0] if (isinstance(lvalue, MemberExpr) and isinstance(lvalue.expr, NameExpr) and lvalue.expr.name == 'self'): results.append(lvalue.name) fdef.accept(SelfTraverser()) return results
def has_return_statement(fdef: FuncBase) -> bool: seeker = ReturnSeeker() fdef.accept(seeker) return seeker.found
def find_self_initializers(fdef: FuncBase) -> List[Tuple[str, Expression]]: traverser = SelfTraverser() fdef.accept(traverser) return traverser.results
def process_base_func(self, node: FuncBase) -> None: self.fixup_type(node.type) node.info = self.fixup(node.info) if node.unanalyzed_type: # Unanalyzed types can have AST node references self.fixup_type(node.unanalyzed_type)
def has_yield_expression(fdef: FuncBase) -> bool: seeker = YieldSeeker() fdef.accept(seeker) return seeker.found