Search in sources :

Example 36 with PyType

use of com.jetbrains.python.psi.types.PyType in project intellij-community by JetBrains.

the class Py3TypeTest method assertType.

private static void assertType(String expectedType, PyExpression expr, TypeEvalContext context) {
    final PyType actual = context.getType(expr);
    final String actualType = PythonDocumentationProvider.getTypeName(actual, context);
    assertEquals(expectedType, actualType);
}
Also used : PyType(com.jetbrains.python.psi.types.PyType)

Example 37 with PyType

use of com.jetbrains.python.psi.types.PyType in project intellij-community by JetBrains.

the class PyClassicPropertyTest method testV3.

public void testV3() throws Exception {
    Maybe<PyCallable> accessor;
    Property p = myClass.findProperty("v3", true, null);
    assertNotNull(p);
    assertNull(p.getDoc());
    PyTargetExpression site = p.getDefinitionSite();
    assertEquals("v3", site.getText());
    accessor = p.getGetter();
    assertFalse(accessor.isDefined());
    final PyType codeInsightType = p.getType(null, TypeEvalContext.codeInsightFallback(myClass.getProject()));
    assertNull(codeInsightType);
    accessor = p.getSetter();
    assertTrue(accessor.isDefined());
    assertNull(accessor.value());
    accessor = p.getDeleter();
    assertTrue(accessor.isDefined());
    assertNotNull(accessor.value());
    assertEquals("deleter", accessor.value().getName());
}
Also used : PyType(com.jetbrains.python.psi.types.PyType)

Example 38 with PyType

use of com.jetbrains.python.psi.types.PyType 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);
    }
}
Also used : PyType(com.jetbrains.python.psi.types.PyType) TypeEvalContext(com.jetbrains.python.psi.types.TypeEvalContext)

Example 39 with PyType

use of com.jetbrains.python.psi.types.PyType in project intellij-community by JetBrains.

the class PyTypingTest method assertType.

private static void assertType(String expectedType, PyExpression expr, TypeEvalContext context, String contextName) {
    final PyType actual = context.getType(expr);
    final String actualType = PythonDocumentationProvider.getTypeName(actual, context);
    assertEquals("Failed in " + contextName + " context", expectedType, actualType);
}
Also used : PyType(com.jetbrains.python.psi.types.PyType)

Example 40 with PyType

use of com.jetbrains.python.psi.types.PyType in project intellij-community by JetBrains.

the class PyStubsTest method doTestUnsupportedNamedTuple.

private void doTestUnsupportedNamedTuple() {
    final PyFile file = getTestFile();
    final PyTargetExpression attribute = file.findTopLevelAttribute("nt");
    assertNotNull(attribute);
    final PyType typeFromStub = TypeEvalContext.codeInsightFallback(myFixture.getProject()).getType(attribute);
    assertNull(typeFromStub);
    assertNotParsed(file);
    final FileASTNode astNode = file.getNode();
    assertNotNull(astNode);
    final PyType typeFromAst = TypeEvalContext.userInitiated(myFixture.getProject(), file).getType(attribute);
    assertNull(typeFromAst);
}
Also used : FileASTNode(com.intellij.lang.FileASTNode) PyType(com.jetbrains.python.psi.types.PyType)

Aggregations

PyType (com.jetbrains.python.psi.types.PyType)42 TypeEvalContext (com.jetbrains.python.psi.types.TypeEvalContext)13 PsiElement (com.intellij.psi.PsiElement)11 Nullable (org.jetbrains.annotations.Nullable)9 PyClassType (com.jetbrains.python.psi.types.PyClassType)6 NotNull (org.jetbrains.annotations.NotNull)6 PsiFile (com.intellij.psi.PsiFile)5 ArrayList (java.util.ArrayList)5 PyClassLikeType (com.jetbrains.python.psi.types.PyClassLikeType)4 PyClassTypeImpl (com.jetbrains.python.psi.types.PyClassTypeImpl)4 NumpyDocString (com.jetbrains.python.documentation.docstrings.NumpyDocString)3 PyExpression (com.jetbrains.python.psi.PyExpression)3 FileASTNode (com.intellij.lang.FileASTNode)2 TextRange (com.intellij.openapi.util.TextRange)2 PsiReference (com.intellij.psi.PsiReference)2 IncorrectOperationException (com.intellij.util.IncorrectOperationException)2 ScopeOwner (com.jetbrains.python.codeInsight.controlflow.ScopeOwner)2 PyClass (com.jetbrains.python.psi.PyClass)2 PyFunctionBuilder (com.jetbrains.python.psi.impl.PyFunctionBuilder)2 PyStructuralType (com.jetbrains.python.psi.types.PyStructuralType)2