SliceExpressionImpl extends PyTree implements SliceExpression, HasTypeDependencies { @Override public InferredType type() { InferredType objectType = object.type(); if (objectType.equals(LIST)) { return LIST; } if (isDeclaredTypeWithTypeClass(objectType, BuiltinTypes.LIST)) { return objectType; } if (objectType.equals(TUPLE)) { return TUPLE; } if (isDeclaredTypeWithTypeClass(objectType, BuiltinTypes.TUPLE)) { return objectType; } return InferredTypes.anyType(); } SliceExpressionImpl(Expression object, Token leftBracket, SliceList sliceList, Token rightBracket); @Override Expression object(); @Override Token leftBracket(); @Override SliceList sliceList(); @Override Token rightBracket(); @Override void accept(TreeVisitor visitor); @Override List<Tree> computeChildren(); @Override Kind getKind(); @Override InferredType type(); @Override List<Expression> typeDependencies();  }
@Test public void type() { assertThat(lastExpression("[42, 43][1:2]").type()).isEqualTo(LIST); assertThat(lastExpression("(42, 43)[1:2]").type()).isEqualTo(TUPLE); assertThat(lastExpression("foo()[1:2]").type()).isEqualTo(InferredTypes.anyType()); assertThat(isDeclaredTypeWithTypeClass(lastExpression( "from typing import List", "def f(x: List[int]): x[1:2]" ).type(), BuiltinTypes.LIST)).isTrue(); assertThat(isDeclaredTypeWithTypeClass(lastExpression( "from typing import Tuple", "def f(x: Tuple[int]): x[1:2]" ).type(), BuiltinTypes.TUPLE)).isTrue(); assertThat(lastExpression( "from typing import Set", "def f(x: Set[int]): x[1:2]" ).type()).isEqualTo(anyType()); }