NameImpl extends PyTree implements Name { @Override public InferredType type() { if (symbol != null && isBooleanBuiltinSymbol()) { return InferredTypes.BOOL; } return inferredType; } NameImpl(Token token, boolean isVariable); @Override String name(); @Override boolean isVariable(); @Override Kind getKind(); @Override void accept(TreeVisitor visitor); @Override List<Tree> computeChildren(); @CheckForNull @Override Symbol symbol(); @CheckForNull @Override Usage usage(); void setSymbol(Symbol symbol); void setUsage(Usage usage); @Override InferredType type(); void setInferredType(InferredType inferredType);  }
@Test public void type() { Token token = new TokenImpl(mock(com.sonar.sslr.api.Token.class)); NameImpl name = new NameImpl(token, true); assertThat(name.type()).isEqualTo(InferredTypes.anyType()); assertThat(name.type()).isEqualTo(InferredTypes.anyType()); InferredType str = InferredTypes.runtimeType(new ClassSymbolImpl("str", "str")); name.setInferredType(str); assertThat(name.type()).isEqualTo(str); }
@Test public void type_of_boolean() { assertThat(PythonTestUtils.lastExpressionInFunction("True").type()).isEqualTo(InferredTypes.BOOL); assertThat(PythonTestUtils.lastExpressionInFunction("False").type()).isEqualTo(InferredTypes.BOOL); assertThat(PythonTestUtils.lastExpressionInFunction( "False = 42", "False" ).type()).isEqualTo(InferredTypes.INT); assertThat(PythonTestUtils.lastExpressionInFunction( "True = '42'", "True" ).type()).isEqualTo(InferredTypes.STR); }