Exemplo n.º 1
0
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
Exemplo n.º 2
0
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
Exemplo n.º 3
0
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
Exemplo n.º 4
0
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
Exemplo n.º 5
0
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
Exemplo n.º 6
0
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
Exemplo n.º 7
0
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
Exemplo n.º 8
0
def has_return_statement(fdef: FuncBase) -> bool:

    seeker = ReturnSeeker()
    fdef.accept(seeker)
    return seeker.found
Exemplo n.º 9
0
def find_self_initializers(fdef: FuncBase) -> List[Tuple[str, Expression]]:
    traverser = SelfTraverser()
    fdef.accept(traverser)
    return traverser.results
Exemplo n.º 10
0
def has_return_statement(fdef: FuncBase) -> bool:
    seeker = ReturnSeeker()
    fdef.accept(seeker)
    return seeker.found
Exemplo n.º 11
0
def find_self_initializers(fdef: FuncBase) -> List[Tuple[str, Expression]]:
    traverser = SelfTraverser()
    fdef.accept(traverser)
    return traverser.results
Exemplo n.º 12
0
def has_yield_expression(fdef: FuncBase) -> bool:
    seeker = YieldSeeker()
    fdef.accept(seeker)
    return seeker.found