From bebe92c8bb69c475dafc0f526d966cfa64596084 Mon Sep 17 00:00:00 2001 From: Ekaterina Tuzova Date: Thu, 27 Jan 2011 18:50:49 +0300 Subject: [PATCH] fixed PY-2797 Py2.4 compatibility: highlight that with statement isn't available in python 2.4 --- .../inspections/PyCompatibilityInspection.java | 5 ++++- .../python/validation/UnsupportedFeatures.java | 6 +++++- .../inspections/PyCompatibilityInspection/test.py | 12 +++++++++--- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/python/src/com/jetbrains/python/inspections/PyCompatibilityInspection.java b/python/src/com/jetbrains/python/inspections/PyCompatibilityInspection.java index 5c4d63bdd0d0..528118421521 100644 --- a/python/src/com/jetbrains/python/inspections/PyCompatibilityInspection.java +++ b/python/src/com/jetbrains/python/inspections/PyCompatibilityInspection.java @@ -433,7 +433,10 @@ public class PyCompatibilityInspection extends PyInspection { StringBuilder message = new StringBuilder(myCommonMessage); for (int i = 0; i != myVersionsToProcess.size(); ++i) { LanguageLevel languageLevel = myVersionsToProcess.get(i); - if (!languageLevel.supportsSetLiterals()) { + if (languageLevel == LanguageLevel.PYTHON24) { + registerProblem(node, "Python version 2.4 doesn't support this syntax."); + } + else if (!languageLevel.supportsSetLiterals()) { final PyWithItem[] items = node.getWithItems(); if (items.length > 1) { for (int j = 1; j < items.length; j++) { diff --git a/python/src/com/jetbrains/python/validation/UnsupportedFeatures.java b/python/src/com/jetbrains/python/validation/UnsupportedFeatures.java index 0deaa91d5d9d..64d11610fdeb 100644 --- a/python/src/com/jetbrains/python/validation/UnsupportedFeatures.java +++ b/python/src/com/jetbrains/python/validation/UnsupportedFeatures.java @@ -271,7 +271,10 @@ public class UnsupportedFeatures extends PyAnnotator { public void visitPyWithStatement(PyWithStatement node) { super.visitPyWithStatement(node); final LanguageLevel languageLevel = getLanguageLevel(node); - if (!languageLevel.supportsSetLiterals()) { + if (languageLevel == LanguageLevel.PYTHON24) { + getHolder().createWarningAnnotation(node, "Python version 2.4 doesn't support this syntax."); + } + else if (!languageLevel.supportsSetLiterals()) { final PyWithItem[] items = node.getWithItems(); if (items.length > 1) { for (int i = 1; i < items.length; i++) { @@ -280,6 +283,7 @@ public class UnsupportedFeatures extends PyAnnotator { } } } + @Override public void visitPyClass(PyClass node) { //PY-2719 if (getLanguageLevel(node) == LanguageLevel.PYTHON24) { diff --git a/python/testData/inspections/PyCompatibilityInspection/test.py b/python/testData/inspections/PyCompatibilityInspection/test.py index fec63feb9933..4c8304c2c186 100644 --- a/python/testData/inspections/PyCompatibilityInspection/test.py +++ b/python/testData/inspections/PyCompatibilityInspection/test.py @@ -14,10 +14,10 @@ class BaseC()< ######################## -with A() as a, B() as b: +with A() as a, B() as b: suite -######################## +######################## a = `imp.acquire_lock()` ######################## @@ -89,4 +89,10 @@ def unified_tef(): else: pass finally: - pass + pass + +######################## +# PY-2797 + +with open("x.txt") as f: + data = f.read()