use of com.jetbrains.python.psi.PyExpression in project intellij-community by JetBrains.
the class PyWithItemImpl method getTarget.
@Override
public PyExpression getTarget() {
ASTNode[] children = getNode().getChildren(null);
boolean foundAs = false;
for (ASTNode child : children) {
if (child.getElementType() == PyTokenTypes.AS_KEYWORD) {
foundAs = true;
} else if (foundAs && child.getPsi() instanceof PyExpression) {
return (PyExpression) child.getPsi();
}
}
return null;
}
use of com.jetbrains.python.psi.PyExpression in project intellij-community by JetBrains.
the class PyYieldExpressionImpl method getType.
@Override
public PyType getType(@NotNull TypeEvalContext context, @NotNull TypeEvalContext.Key key) {
final PyExpression e = getExpression();
PyType type = e != null ? context.getType(e) : null;
if (isDelegating()) {
final PyClassLikeType classType = as(type, PyClassLikeType.class);
final PyCollectionType collectionType = as(type, PyCollectionType.class);
if (classType != null && collectionType != null) {
if (PyTypingTypeProvider.GENERATOR.equals(classType.getClassQName())) {
final List<PyType> elementTypes = collectionType.getElementTypes(context);
if (elementTypes.size() == 3) {
return elementTypes.get(2);
}
}
}
return PyNoneType.INSTANCE;
}
return type;
}
use of com.jetbrains.python.psi.PyExpression in project intellij-community by JetBrains.
the class PyConditionalExpressionImpl method getType.
public PyType getType(@NotNull TypeEvalContext context, @NotNull TypeEvalContext.Key key) {
final PyExpression truePart = getTruePart();
final PyExpression falsePart = getFalsePart();
if (truePart == null || falsePart == null) {
return null;
}
return PyUnionType.union(context.getType(truePart), context.getType(falsePart));
}
use of com.jetbrains.python.psi.PyExpression in project intellij-community by JetBrains.
the class PyListLiteralExpressionImpl method add.
public PsiElement add(@NotNull PsiElement psiElement) throws IncorrectOperationException {
checkPyExpression(psiElement);
PyExpression element = (PyExpression) psiElement;
PyExpression[] els = getElements();
PyExpression lastArg = els.length == 0 ? null : els[els.length - 1];
return PyElementGenerator.getInstance(getProject()).insertItemIntoList(this, lastArg, element);
}
use of com.jetbrains.python.psi.PyExpression in project intellij-community by JetBrains.
the class PyFunctionTypeAnnotationParsingTest method testEllipsis.
public void testEllipsis() {
doCodeTest("(...) -> None");
final PyFunctionTypeAnnotation annotation = getParsedAnnotation();
final List<PyExpression> paramTypes = annotation.getParameterTypeList().getParameterTypes();
assertSize(1, paramTypes);
assertInstanceOf(paramTypes.get(0), PyNoneLiteralExpression.class);
final PyExpression returnType = annotation.getReturnType();
assertNotNull(returnType);
}
Aggregations