mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-20 05:21:29 +07:00
PY-80169 Conformance test failure: exceptions_context_managers.py
(cherry picked from commit 7d43529ffe01edc695ed2e3682ab38960df45961) GitOrigin-RevId: 94259cd855bf74a032b764de478483a90fba2578
This commit is contained in:
committed by
intellij-monorepo-bot
parent
8ddb666032
commit
8b35c2619c
@@ -27,6 +27,7 @@ import com.jetbrains.python.nameResolver.NameResolverTools;
|
||||
import com.jetbrains.python.psi.*;
|
||||
import com.jetbrains.python.psi.resolve.PyResolveContext;
|
||||
import com.jetbrains.python.psi.types.TypeEvalContext;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -96,7 +97,7 @@ public class PyEvaluator {
|
||||
else if (expression instanceof PySequenceExpression) {
|
||||
return evaluateSequence((PySequenceExpression)expression);
|
||||
}
|
||||
final Boolean bool = evaluateBoolean(expression);
|
||||
final Boolean bool = getBooleanLiteralValue(expression);
|
||||
if (bool != null) {
|
||||
return bool;
|
||||
}
|
||||
@@ -180,7 +181,8 @@ public class PyEvaluator {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static @Nullable Boolean evaluateBoolean(@NotNull PyExpression expression) {
|
||||
@ApiStatus.Internal
|
||||
public static @Nullable Boolean getBooleanLiteralValue(@NotNull PsiElement expression) {
|
||||
if (expression instanceof PyBoolLiteralExpression) {
|
||||
if (PyNames.DEBUG.equals(expression.getText())) {
|
||||
return null;
|
||||
|
||||
@@ -269,9 +269,7 @@ class PyLiteralType private constructor(cls: PyClass, val expression: PyExpressi
|
||||
if (operand is PyNumericLiteralExpression && operand.isIntegerLiteral) getPyClass(operand, context) else null
|
||||
}
|
||||
|
||||
expression is PyReferenceExpression &&
|
||||
expression.name.let { it == PyNames.TRUE || it == PyNames.FALSE } &&
|
||||
LanguageLevel.forElement(expression).isPython2 -> getPyClass(expression, context)
|
||||
PyEvaluator.getBooleanLiteralValue(expression) != null -> getPyClass(expression, context)
|
||||
|
||||
else -> null
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import com.jetbrains.python.PyNames;
|
||||
import com.jetbrains.python.PyTokenTypes;
|
||||
import com.jetbrains.python.PythonLanguage;
|
||||
import com.jetbrains.python.psi.*;
|
||||
import com.jetbrains.python.psi.impl.PyEvaluator;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -124,14 +125,9 @@ public final class PyInvertBooleanDelegate extends InvertBooleanDelegate {
|
||||
|
||||
private static @NotNull PyExpression invertExpression(final @NotNull PsiElement expression) {
|
||||
final PyElementGenerator elementGenerator = PyElementGenerator.getInstance(expression.getProject());
|
||||
if (expression instanceof PyBoolLiteralExpression) {
|
||||
final String value = ((PyBoolLiteralExpression)expression).getValue() ? PyNames.FALSE : PyNames.TRUE;
|
||||
return elementGenerator.createExpressionFromText(LanguageLevel.forElement(expression), value);
|
||||
}
|
||||
if (expression instanceof PyReferenceExpression && (PyNames.FALSE.equals(expression.getText()) ||
|
||||
PyNames.TRUE.equals(expression.getText()))) {
|
||||
|
||||
final String value = PyNames.TRUE.equals(expression.getText()) ? PyNames.FALSE : PyNames.TRUE;
|
||||
Boolean booleanValue = PyEvaluator.getBooleanLiteralValue(expression);
|
||||
if (booleanValue != null) {
|
||||
final String value = booleanValue ? PyNames.FALSE : PyNames.TRUE;
|
||||
return elementGenerator.createExpressionFromText(LanguageLevel.forElement(expression), value);
|
||||
}
|
||||
else if (expression instanceof PyPrefixExpression) {
|
||||
@@ -145,9 +141,6 @@ public final class PyInvertBooleanDelegate extends InvertBooleanDelegate {
|
||||
}
|
||||
|
||||
private static boolean isBooleanLiteral(@Nullable PsiElement element) {
|
||||
if (element instanceof PyBoolLiteralExpression) {
|
||||
return true;
|
||||
}
|
||||
return element instanceof PyReferenceExpression && (PyNames.TRUE.equals(element.getText()) || PyNames.FALSE.equals(element.getText()));
|
||||
return element != null && PyEvaluator.getBooleanLiteralValue(element) != null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user