diff --git a/python/src/com/jetbrains/python/inspections/PyCompatibilityInspection.java b/python/src/com/jetbrains/python/inspections/PyCompatibilityInspection.java index 7c853508f729..a0fe21d7f8b5 100644 --- a/python/src/com/jetbrains/python/inspections/PyCompatibilityInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyCompatibilityInspection.java @@ -20,6 +20,7 @@ import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Set; +import java.util.Stack; import java.util.Vector; /** @@ -572,10 +573,24 @@ public class PyCompatibilityInspection extends PyInspection { } @Override - public void visitPyAssignmentStatement(PyAssignmentStatement node) { // PY-2792 + public void visitPyAssignmentStatement(PyAssignmentStatement node) { if (myVersionsToProcess.contains(LanguageLevel.PYTHON24)) { - if (node.getAssignedValue() instanceof PyConditionalExpression) + PyExpression assignedValue = node.getAssignedValue(); + if (assignedValue instanceof PyConditionalExpression) // PY-2792 registerProblem(node, "Python version 2.4 doesn't support this syntax."); + + Stack st = new Stack(); // PY-2796 + st.push(assignedValue); + while (!st.isEmpty()) { + PsiElement el = st.pop(); + if (el instanceof PyYieldExpression) + registerProblem(node, "Python version 2.4 doesn't support this syntax." + + "In Python <= 2.4, yield was a statement; it didn’t return any value."); + else { + for (PsiElement e : el.getChildren()) + st.push(e); + } + } } } diff --git a/python/src/com/jetbrains/python/validation/UnsupportedFeatures.java b/python/src/com/jetbrains/python/validation/UnsupportedFeatures.java index c3f999d254c0..079cd7e9e87a 100644 --- a/python/src/com/jetbrains/python/validation/UnsupportedFeatures.java +++ b/python/src/com/jetbrains/python/validation/UnsupportedFeatures.java @@ -20,6 +20,7 @@ import com.jetbrains.python.psi.impl.PyQualifiedName; import org.jetbrains.annotations.NotNull; import java.util.List; +import java.util.Stack; /** * @author Alexey.Ivanov @@ -298,6 +299,7 @@ public class UnsupportedFeatures extends PyAnnotator { } } } + @Override public void visitPyFromImportStatement(PyFromImportStatement node) { PyReferenceExpression importSource = node.getImportSource(); @@ -306,21 +308,38 @@ public class UnsupportedFeatures extends PyAnnotator { getHolder().createWarningAnnotation(node, "Python version 2.4 doesn't support this syntax."); } } + @Override - public void visitPyAssignmentStatement(PyAssignmentStatement node) { // PY-2792 + public void visitPyAssignmentStatement(PyAssignmentStatement node) { if (getLanguageLevel(node) == LanguageLevel.PYTHON24) { - if (node.getAssignedValue() instanceof PyConditionalExpression) + PyExpression assignedValue = node.getAssignedValue(); + if (assignedValue instanceof PyConditionalExpression) // PY-2792 getHolder().createWarningAnnotation(node, "Python version 2.4 doesn't support this syntax."); + + Stack st = new Stack(); // PY-2796 + st.push(assignedValue); + while (!st.isEmpty()) { + PsiElement el = st.pop(); + if (el instanceof PyYieldExpression) + getHolder().createWarningAnnotation(node, "Python version 2.4 doesn't support this syntax." + + "In Python <= 2.4, yield was a statement; it didn’t return any value."); + else { + for (PsiElement e : el.getChildren()) + st.push(e); + } + } } } + @Override public void visitPyTryExceptStatement(PyTryExceptStatement node) { // PY-2795 if (getLanguageLevel(node) == LanguageLevel.PYTHON24) { PyExceptPart[] excepts = node.getExceptParts(); PyFinallyPart finallyPart = node.getFinallyPart(); if (excepts.length != 0 && finallyPart != null) - getHolder().createWarningAnnotation(node, "Python version 2.4 doesn't support this syntax. You could use a finally block to ensure " + - "that code is always executed, or one or more except blocks to catch specific exceptions."); + getHolder().createWarningAnnotation(node, + "Python version 2.4 doesn't support this syntax. You could use a finally block to ensure " + + "that code is always executed, or one or more except blocks to catch specific exceptions."); } } }