mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Fix doing type assertions for <ref> is <ref> statements, None should be presented on one side only (PY-29748)
This commit is contained in:
+10
-12
@@ -103,20 +103,18 @@ public class PyTypeAssertionEvaluator extends PyRecursiveElementVisitor {
|
||||
final boolean leftIsNone = lhs instanceof PyNoneLiteralExpression || PyNames.NONE.equals(lhs.getName());
|
||||
final boolean rightIsNone = rhs instanceof PyNoneLiteralExpression || PyNames.NONE.equals(rhs.getName());
|
||||
|
||||
if (leftIsNone && rightIsNone) {
|
||||
return;
|
||||
}
|
||||
if (leftIsNone ^ rightIsNone) {
|
||||
final PyReferenceExpression target = (PyReferenceExpression)(rightIsNone ? lhs : rhs);
|
||||
|
||||
final PyReferenceExpression target = (PyReferenceExpression)(rightIsNone ? lhs : rhs);
|
||||
if (node.isOperator(PyNames.IS)) {
|
||||
pushAssertion(target, myPositive, false, context -> PyNoneType.INSTANCE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (node.isOperator(PyNames.IS)) {
|
||||
pushAssertion(target, myPositive, false, context -> PyNoneType.INSTANCE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (node.isOperator("isnot")) {
|
||||
pushAssertion(target, !myPositive, false, context -> PyNoneType.INSTANCE);
|
||||
return;
|
||||
if (node.isOperator("isnot")) {
|
||||
pushAssertion(target, !myPositive, false, context -> PyNoneType.INSTANCE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3244,6 +3244,14 @@ public class PyTypeTest extends PyTestCase {
|
||||
"expr = T");
|
||||
}
|
||||
|
||||
// PY-29748
|
||||
public void testAfterIdentityComparison() {
|
||||
doTest("int",
|
||||
"a = 1\n" +
|
||||
"if a is a:\n" +
|
||||
" expr = a");
|
||||
}
|
||||
|
||||
private static List<TypeEvalContext> getTypeEvalContexts(@NotNull PyExpression element) {
|
||||
return ImmutableList.of(TypeEvalContext.codeAnalysis(element.getProject(), element.getContainingFile()).withTracing(),
|
||||
TypeEvalContext.userInitiated(element.getProject(), element.getContainingFile()).withTracing());
|
||||
|
||||
Reference in New Issue
Block a user