fixed PY-2795 Python 2.4 compatibility: Unified try/except/finally: missing inspection

This commit is contained in:
Ekaterina Tuzova
2011-01-27 17:57:19 +03:00
parent 965ddc5059
commit 68762c3320
2 changed files with 23 additions and 3 deletions
@@ -572,11 +572,22 @@ public class PyCompatibilityInspection extends PyInspection {
}
@Override
public void visitPyAssignmentStatement(PyAssignmentStatement node) {
public void visitPyAssignmentStatement(PyAssignmentStatement node) { // PY-2792
if (myVersionsToProcess.contains(LanguageLevel.PYTHON24)) {
if (node.getAssignedValue() instanceof PyConditionalExpression)
registerProblem(node, "Python version 2.4 doesn't support this syntax.");
}
}
@Override
public void visitPyTryExceptStatement(PyTryExceptStatement node) { // PY-2795
if (myVersionsToProcess.contains(LanguageLevel.PYTHON24)) {
PyExceptPart[] excepts = node.getExceptParts();
PyFinallyPart finallyPart = node.getFinallyPart();
if (excepts.length != 0 && finallyPart != null)
registerProblem(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.");
}
}
}
}
@@ -307,11 +307,20 @@ public class UnsupportedFeatures extends PyAnnotator {
}
}
@Override
public void visitPyAssignmentStatement(PyAssignmentStatement node) {
public void visitPyAssignmentStatement(PyAssignmentStatement node) { // PY-2792
if (getLanguageLevel(node) == LanguageLevel.PYTHON24) {
if (node.getAssignedValue() instanceof PyConditionalExpression)
getHolder().createWarningAnnotation(node, "Python version 2.4 doesn't support this syntax.");
}
}
@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.");
}
}
}