*/
package com.jetbrains.python.codeInsight.intentions;
-import com.intellij.openapi.util.Condition;
import com.intellij.util.containers.ContainerUtil;
-import com.jetbrains.python.psi.*;
+import com.jetbrains.python.psi.LanguageLevel;
+import com.jetbrains.python.psi.PySequenceExpression;
+import com.jetbrains.python.psi.PySetLiteralExpression;
+import com.jetbrains.python.psi.PyTargetExpression;
import org.jetbrains.annotations.NotNull;
/**
}
@Override
- protected boolean isAvailableForCollection(PySequenceExpression literal) {
- return LanguageLevel.forElement(literal).isAtLeast(LanguageLevel.PYTHON27) && !isInTargetPosition(literal);
+ protected boolean isAvailableForCollection(@NotNull PySequenceExpression literal) {
+ return !literal.isEmpty() && LanguageLevel.forElement(literal).isAtLeast(LanguageLevel.PYTHON27) && !isInTargetPosition(literal);
}
- private static boolean isInTargetPosition(@NotNull final PySequenceExpression sequenceLiteral) {
- return ContainerUtil.exists(sequenceLiteral.getElements(), new Condition<PyExpression>() {
- @Override
- public boolean value(PyExpression expression) {
- return expression instanceof PyTargetExpression;
- }
- });
+ private static boolean isInTargetPosition(@NotNull PySequenceExpression sequenceLiteral) {
+ return ContainerUtil.exists(sequenceLiteral.getElements(), expression -> expression instanceof PyTargetExpression);
}
}
public void testConvertOneElementTupleWithCommentToList() {
doIntentionTest(CONVERT_TUPLE_TO_LIST);
}
+
+ // PY-19399
+ public void testCannotConvertEmptyTupleToSet() {
+ doNegativeTest(CONVERT_TUPLE_TO_SET);
+ }
+
+ // PY-19399
+ public void testCannotConvertEmptyListToSet() {
+ doNegativeTest(CONVERT_LIST_TO_SET);
+ }
}