ComprehensionExpressionImpl extends PyTree implements ComprehensionExpression { @Override public InferredType type() { switch (kind) { case LIST_COMPREHENSION: return InferredTypes.LIST; case SET_COMPREHENSION: return InferredTypes.SET; default: return InferredTypes.anyType(); } } ComprehensionExpressionImpl(Kind kind, @Nullable Token openingToken, Expression resultExpression,
                                     ComprehensionFor compFor, @Nullable Token closingToken); @Override Expression resultExpression(); @Override ComprehensionFor comprehensionFor(); @Override Set<Symbol> localVariables(); @Override void accept(TreeVisitor visitor); @Override List<Tree> computeChildren(); @Override Kind getKind(); void addLocalVariableSymbol(Symbol symbol); @Override InferredType type();  }
@Test public void type() { Token token = mock(Token.class); Expression resultExpression = mock(Expression.class); ComprehensionFor compFor = mock(ComprehensionFor.class); ComprehensionExpressionImpl generator = new ComprehensionExpressionImpl(Kind.GENERATOR_EXPR, token, resultExpression, compFor, token); assertThat(generator.type()).isEqualTo(InferredTypes.anyType()); ComprehensionExpressionImpl listComp = new ComprehensionExpressionImpl(Kind.LIST_COMPREHENSION, token, resultExpression, compFor, token); assertThat(listComp.type()).isEqualTo(InferredTypes.LIST); ComprehensionExpressionImpl setComp = new ComprehensionExpressionImpl(Kind.SET_COMPREHENSION, token, resultExpression, compFor, token); assertThat(setComp.type()).isEqualTo(InferredTypes.SET); ComprehensionExpressionImpl comprehensionExpression = new ComprehensionExpressionImpl(Kind.NAME, token, resultExpression, compFor, token); assertThat(comprehensionExpression.type()).isEqualTo(InferredTypes.anyType()); }