use of com.jetbrains.python.psi.types.TypeEvalContext in project intellij-community by JetBrains.
the class PyTypeTest method checkTypes.
private static void checkTypes(@NotNull String expectedType, @Nullable PyExpression expr) {
assertNotNull(expr);
for (TypeEvalContext context : getTypeEvalContexts(expr)) {
final PyType actual = context.getType(expr);
final String actualType = PythonDocumentationProvider.getTypeName(actual, context);
assertEquals("Failed in " + context, expectedType, actualType);
}
}
use of com.jetbrains.python.psi.types.TypeEvalContext in project intellij-community by JetBrains.
the class PyTypingTest method doTest.
private void doTest(@NotNull String expectedType, @NotNull String text) {
myFixture.copyDirectoryToProject("typing", "");
myFixture.configureByText(PythonFileType.INSTANCE, text);
final PyExpression expr = myFixture.findElementByText("expr", PyExpression.class);
final TypeEvalContext codeAnalysis = TypeEvalContext.codeAnalysis(expr.getProject(), expr.getContainingFile());
final TypeEvalContext userInitiated = TypeEvalContext.userInitiated(expr.getProject(), expr.getContainingFile()).withTracing();
assertType(expectedType, expr, codeAnalysis, "code analysis");
assertType(expectedType, expr, userInitiated, "user initiated");
}
use of com.jetbrains.python.psi.types.TypeEvalContext in project intellij-community by JetBrains.
the class PyStubsTest method testVariableAnnotationsInExternalFiles.
public void testVariableAnnotationsInExternalFiles() {
runWithLanguageLevel(LanguageLevel.PYTHON36, () -> {
final PyFile current = getTestFile(getTestName(true) + "/main.py");
final PyFile external = getTestFile(getTestName(true) + "/lib.py");
final PyTargetExpression attr = current.findTopLevelAttribute("x");
assertNotNull(attr);
final TypeEvalContext context = TypeEvalContext.codeAnalysis(myFixture.getProject(), current);
// Will turn into concrete type when we start saving annotations in stubs
assertNull(context.getType(attr));
assertNotParsed(external);
});
}
use of com.jetbrains.python.psi.types.TypeEvalContext in project intellij-community by JetBrains.
the class PyStubsTest method testMetaClass.
public void testMetaClass() {
final PyFile file = getTestFile();
final PyClass c = file.findTopLevelClass("C");
assertNotNull(c);
final TypeEvalContext context = TypeEvalContext.codeInsightFallback(myFixture.getProject());
assertNotNull(c.getMetaClassType(context));
final PyClass d = file.findTopLevelClass("D");
assertNotNull(d);
assertNotNull(d.getMetaClassType(context));
assertNotParsed(file);
}
Aggregations