From 68762c332025dda1e70e01ac84e10e292623c73e Mon Sep 17 00:00:00 2001 From: Ekaterina Tuzova Date: Thu, 27 Jan 2011 17:57:19 +0300 Subject: [PATCH] fixed PY-2795 Python 2.4 compatibility: Unified try/except/finally: missing inspection --- .../inspections/PyCompatibilityInspection.java | 13 ++++++++++++- .../python/validation/UnsupportedFeatures.java | 13 +++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/python/src/com/jetbrains/python/inspections/PyCompatibilityInspection.java b/python/src/com/jetbrains/python/inspections/PyCompatibilityInspection.java index ccc105fe5452..7c853508f729 100644 --- a/python/src/com/jetbrains/python/inspections/PyCompatibilityInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyCompatibilityInspection.java @@ -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."); + } + } } } diff --git a/python/src/com/jetbrains/python/validation/UnsupportedFeatures.java b/python/src/com/jetbrains/python/validation/UnsupportedFeatures.java index 176516c7f4da..c3f999d254c0 100644 --- a/python/src/com/jetbrains/python/validation/UnsupportedFeatures.java +++ b/python/src/com/jetbrains/python/validation/UnsupportedFeatures.java @@ -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."); + } + } }