Esempio n. 1
0
  def _CompFor(self, p_node):
    # type: (PNode) -> comprehension
    """
    comp_for: 'for' exprlist 'in' or_test ['if' or_test]
    """
    children = p_node.children

    lhs = self._NameTypeList(children[1])  # Python calls this target
    iterable = self.Expr(children[3])

    if len(children) >= 6:
      cond = self.Expr(children[5])
    else:
      cond = None

    return comprehension(lhs, iterable, cond)
Esempio n. 2
0
  def _CompFor(self, p_node):
    # type: (PNode) -> comprehension
    """
    comp_for: 'for' exprlist 'in' or_test ['if' test_nocond]
    """
    children = p_node.children

    lvalue = self.Expr(children[1])  # Python calls this target
    iterable = self.Expr(children[3])

    if_ = None
    if len(children) >= 6:
      if_ = self.Expr(children[5])

    # TODO: Simplify the node
    ifs = [if_] if if_ else []
    return comprehension(lvalue, iterable, ifs)