mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Move highlighting continue under finally to compatibility inspection (PY-36003)
GitOrigin-RevId: d644848d69b91c4ee05f1342f804e58ea137aac2
This commit is contained in:
committed by
intellij-monorepo-bot
parent
bf2f4468b2
commit
34ae8b9265
@@ -773,7 +773,6 @@ ANN.cant.assign.to.lambda=Can't assign to lambda
|
||||
|
||||
ANN.break.outside.loop='break' outside loop
|
||||
ANN.continue.outside.loop='continue' outside loop
|
||||
ANN.cant.continue.in.finally='continue' not supported inside 'finally' clause
|
||||
ANN.default.except.must.be.last=default 'except:' must be last
|
||||
|
||||
ANN.$0.both.global.and.param=Name ''{0}'' used both as a parameter and as a global
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
*/
|
||||
package com.jetbrains.python.validation;
|
||||
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.jetbrains.python.psi.*;
|
||||
import com.jetbrains.python.psi.PyBreakStatement;
|
||||
import com.jetbrains.python.psi.PyContinueStatement;
|
||||
|
||||
import static com.jetbrains.python.PyBundle.message;
|
||||
|
||||
@@ -36,9 +36,5 @@ public class BreakContinueAnnotator extends PyAnnotator {
|
||||
if (node.getLoopStatement() == null) {
|
||||
getHolder().createErrorAnnotation(node, message("ANN.continue.outside.loop"));
|
||||
}
|
||||
else if (LanguageLevel.forElement(node).isOlderThan(LanguageLevel.PYTHON38) &&
|
||||
PsiTreeUtil.getParentOfType(node, PyFinallyPart.class, false, PyLoopStatement.class) != null) {
|
||||
getHolder().createErrorAnnotation(node, message("ANN.cant.continue.in.finally"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -709,4 +709,15 @@ public abstract class CompatibilityVisitor extends PyAnnotator {
|
||||
registerForAllMatchingVersions(level -> level.isOlderThan(LanguageLevel.PYTHON38) && registerForLanguageLevel(level),
|
||||
" not support assignment expressions", node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitPyContinueStatement(PyContinueStatement node) {
|
||||
super.visitPyContinueStatement(node);
|
||||
|
||||
if (PsiTreeUtil.getParentOfType(node, PyFinallyPart.class, false, PyLoopStatement.class) != null) {
|
||||
registerForAllMatchingVersions(level -> level.isOlderThan(LanguageLevel.PYTHON38) && registerForLanguageLevel(level),
|
||||
" not support 'continue' inside 'finally' clause",
|
||||
node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,4 +2,4 @@ while True:
|
||||
try:
|
||||
print("a")
|
||||
finally:
|
||||
<error descr="'continue' not supported inside 'finally' clause">continue</error>
|
||||
<error descr="Python version 3.7 does not support 'continue' inside 'finally' clause">continue</error>
|
||||
@@ -240,6 +240,18 @@ public class PyCompatibilityInspectionTest extends PyInspectionTestCase {
|
||||
doTest(LanguageLevel.PYTHON38);
|
||||
}
|
||||
|
||||
// PY-36003
|
||||
public void testContinueInFinallyBlock() {
|
||||
runWithLanguageLevel(
|
||||
LanguageLevel.PYTHON38,
|
||||
() -> doTestByText("while True:\n" +
|
||||
" try:\n" +
|
||||
" print(\"a\")\n" +
|
||||
" finally:\n" +
|
||||
" <warning descr=\"Python version 2.6, 2.7, 3.4, 3.5, 3.6, 3.7 do not support 'continue' inside 'finally' clause\">continue</warning>")
|
||||
);
|
||||
}
|
||||
|
||||
private void doTest(@NotNull LanguageLevel level) {
|
||||
runWithLanguageLevel(level, this::doTest);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user