fixed PY-3245 Should complain about named param after *args on Python ≤2.5

This commit is contained in:
Ekaterina Tuzova
2012-05-14 17:48:15 +04:00
parent cd2723075a
commit f9de665198
3 changed files with 26 additions and 2 deletions
@@ -430,6 +430,17 @@ public abstract class CompatibilityVisitor extends PyAnnotator {
super.visitPyCallExpression(node);
int len = 0;
StringBuilder message = new StringBuilder(myCommonMessage);
if (myVersionsToProcess.contains(LanguageLevel.PYTHON24) || myVersionsToProcess.contains(LanguageLevel.PYTHON25)) {
boolean hasStar = false;
for (PyExpression argument : node.getArguments()) {
if (hasStar && argument instanceof PyKeywordArgument) {
registerProblem(argument, "Python version < 2.6 doesn't support this syntax. Named parameter cannot appear past *arg or **kwarg.");
}
if (argument instanceof PyStarArgument) hasStar = true;
}
}
for (int i = 0; i != myVersionsToProcess.size(); ++i) {
LanguageLevel languageLevel = myVersionsToProcess.get(i);
if (!languageLevel.isPy3K()) {
@@ -6,4 +6,11 @@ class A(B):
<warning descr="Python version 3.0, 3.1 do not have method reduce">reduce()</warning>
<warning descr="Python version 2.4 does not have method all">all()</warning>
<warning descr="Python version 3.0, 3.1 do not have method buffer">buffer()</warning>
<warning descr="Python version 3.0, 3.1 do not have method buffer">buffer()</warning>
def foo(a,b,c):
print (a,b,c)
args=['b']
foo('a', c='c', *args) # OK
foo('a', *args, <warning descr="Python version < 2.6 doesn't support this syntax. Named parameter cannot appear past *arg or **kwarg.">c='c'</warning>) # Not OK
@@ -49,7 +49,13 @@ public class PyArgumentListInspectionTest extends PyTestCase {
}
public void testPy1268() {
doTest();
PythonLanguageLevelPusher.setForcedLanguageLevel(myFixture.getProject(), LanguageLevel.PYTHON30);
try {
doTest();
}
finally {
PythonLanguageLevelPusher.setForcedLanguageLevel(myFixture.getProject(), null);
}
}
public void testInstanceMethodAsLambda() {