fixed PY-2797 Py2.4 compatibility: highlight that with statement isn't available in python 2.4

This commit is contained in:
Ekaterina Tuzova
2011-01-27 18:50:49 +03:00
parent d3dc22f32d
commit bebe92c8bb
3 changed files with 18 additions and 5 deletions
@@ -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++) {
@@ -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) {
@@ -14,10 +14,10 @@ class BaseC<warning descr="Python version 2.4 does not support this syntax.">()<
########################
with A() as a, <warning descr="Python versions 2.4, 2.5, 2.6, 3.0 do not support multiple context managers">B() as b</warning>:
<warning descr="Python version 2.4 doesn't support this syntax.">with A() as a, <warning descr="Python versions 2.5, 2.6, 3.0 do not support multiple context managers">B() as b</warning>:
suite
########################
</warning>########################
a = <warning descr="Python versions 3.0, 3.1 do not support backquotes, use repr() instead">`imp.acquire_lock()`</warning>
########################
@@ -89,4 +89,10 @@ def unified_tef():
else:
pass
finally:
pass</warning>
pass
</warning>########################
# PY-2797
<warning descr="Python version 2.4 doesn't support this syntax.">with open("x.txt") as f:
data = f.read()</warning>