mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
highlight assignments as 'with' statement target as error (PY-7529)
This commit is contained in:
@@ -257,4 +257,8 @@ public class PyElementVisitor extends PsiElementVisitor {
|
||||
public void visitPyKeywordArgument(PyKeywordArgument node) {
|
||||
visitPyElement(node);
|
||||
}
|
||||
|
||||
public void visitPyWithItem(PyWithItem node) {
|
||||
visitPyElement(node);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.jetbrains.python.psi.impl;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.jetbrains.python.PyTokenTypes;
|
||||
import com.jetbrains.python.psi.PyElementVisitor;
|
||||
import com.jetbrains.python.psi.PyExpression;
|
||||
import com.jetbrains.python.psi.PyWithItem;
|
||||
|
||||
@@ -14,6 +15,11 @@ public class PyWithItemImpl extends PyElementImpl implements PyWithItem {
|
||||
super(astNode);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void acceptPyVisitor(PyElementVisitor pyVisitor) {
|
||||
pyVisitor.visitPyWithItem(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PyExpression getExpression() {
|
||||
ASTNode[] children = getNode().getChildren(null);
|
||||
|
||||
@@ -12,7 +12,7 @@ import static com.jetbrains.python.PyBundle.message;
|
||||
*/
|
||||
public class AssignTargetAnnotator extends PyAnnotator {
|
||||
private enum Operation {
|
||||
Assign, AugAssign, Delete, Except, For
|
||||
Assign, AugAssign, Delete, Except, For, With
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -51,6 +51,14 @@ public class AssignTargetAnnotator extends PyAnnotator {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitPyWithItem(PyWithItem node) {
|
||||
PyExpression target = node.getTarget();
|
||||
if (target != null) {
|
||||
target.accept(new ExprVisitor(Operation.With));
|
||||
}
|
||||
}
|
||||
|
||||
private class ExprVisitor extends PyElementVisitor {
|
||||
private final Operation myOp;
|
||||
private final String DELETING_NONE = message("ANN.deleting.none");
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
with open("") as <error descr="can't assign to operator">my_<<var</error>:
|
||||
pass
|
||||
@@ -65,6 +65,11 @@ public class PythonHighlightingTest extends PyTestCase {
|
||||
doTest(true, false);
|
||||
}
|
||||
|
||||
public void testAssignmentTargetWith() { // PY-7529
|
||||
setLanguageLevel(LanguageLevel.PYTHON27);
|
||||
doTest(true, false);
|
||||
}
|
||||
|
||||
public void testAssignmentTargets3K() {
|
||||
doTest(LanguageLevel.PYTHON30, true, false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user