diff --git a/python/src/com/jetbrains/python/inspections/PyCompatibilityInspection.java b/python/src/com/jetbrains/python/inspections/PyCompatibilityInspection.java
index ce0e5372b8f3..bf2d523c5437 100644
--- a/python/src/com/jetbrains/python/inspections/PyCompatibilityInspection.java
+++ b/python/src/com/jetbrains/python/inspections/PyCompatibilityInspection.java
@@ -3,10 +3,16 @@ package com.jetbrains.python.inspections;
import com.intellij.codeInspection.LocalQuickFix;
import com.intellij.codeInspection.ProblemsHolder;
import com.intellij.openapi.application.ApplicationManager;
+import com.intellij.openapi.roots.ProjectFileIndex;
+import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
+import com.intellij.psi.PsiFile;
+import com.intellij.psi.PsiReference;
import com.jetbrains.python.PyBundle;
import com.jetbrains.python.psi.LanguageLevel;
+import com.jetbrains.python.psi.PyCallExpression;
+import com.jetbrains.python.psi.PyExpression;
import com.jetbrains.python.validation.CompatibilityVisitor;
import com.jetbrains.python.validation.UnsupportedFeaturesUtil;
import org.jetbrains.annotations.Nls;
@@ -120,5 +126,39 @@ public class PyCompatibilityInspection extends PyInspection {
else
myHolder.registerProblem(element, message);
}
+
+ @Override
+ public void visitPyCallExpression(PyCallExpression node) {
+ super.visitPyCallExpression(node);
+
+ int len = 0;
+ StringBuilder message = new StringBuilder("Python version ");
+ for (int i = 0; i != myVersionsToProcess.size(); ++i) {
+ LanguageLevel languageLevel = myVersionsToProcess.get(i);
+ PyExpression callee = node.getCallee();
+ assert callee != null;
+ PsiReference reference = callee.getReference();
+ if (reference != null) {
+ PsiElement resolved = reference.resolve();
+ ProjectFileIndex ind = ProjectRootManager.getInstance(callee.getProject()).getFileIndex();
+ final String name = callee.getText();
+ if (resolved != null) {
+ PsiFile file = resolved.getContainingFile();
+ if (file != null && ind.isInLibraryClasses(file.getVirtualFile())) {
+ if (!name.equals("print") && UnsupportedFeaturesUtil.BUILTINS.get(languageLevel).contains(name)) {
+ len = appendLanguageLevel(message, len, languageLevel);
+ }
+ }
+ }
+ //else {
+ // if (!name.equals("print") && UnsupportedFeaturesUtil.BUILTINS.get(languageLevel).contains(name)) {
+ // len = appendLanguageLevel(message, len, languageLevel);
+ // }
+ //}
+ }
+ }
+ commonRegisterProblem(message, " not have method " + node.getCallee().getText(),
+ len, node, null, false);
+ }
}
}
diff --git a/python/src/com/jetbrains/python/validation/CompatibilityVisitor.java b/python/src/com/jetbrains/python/validation/CompatibilityVisitor.java
index 0b5914f5b3bd..470f90aed35b 100644
--- a/python/src/com/jetbrains/python/validation/CompatibilityVisitor.java
+++ b/python/src/com/jetbrains/python/validation/CompatibilityVisitor.java
@@ -1,11 +1,7 @@
package com.jetbrains.python.validation;
import com.intellij.codeInspection.LocalQuickFix;
-import com.intellij.openapi.roots.ProjectFileIndex;
-import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.psi.PsiElement;
-import com.intellij.psi.PsiFile;
-import com.intellij.psi.PsiReference;
import com.intellij.psi.PsiWhiteSpace;
import com.jetbrains.python.PyNames;
import com.jetbrains.python.PyTokenTypes;
@@ -421,34 +417,6 @@ public abstract class CompatibilityVisitor extends PyAnnotator {
}
commonRegisterProblem(message, " not support this syntax. super() should have arguments in Python 2",
len, node, null);
- len = 0;
- message = new StringBuilder(myCommonMessage);
- for (int i = 0; i != myVersionsToProcess.size(); ++i) {
- LanguageLevel languageLevel = myVersionsToProcess.get(i);
- PyExpression callee = node.getCallee();
- assert callee != null;
- PsiReference reference = callee.getReference();
- if (reference != null) {
- PsiElement resolved = reference.resolve();
- ProjectFileIndex ind = ProjectRootManager.getInstance(callee.getProject()).getFileIndex();
- final String name = callee.getText();
- if (resolved != null) {
- PsiFile file = resolved.getContainingFile();
- if (file != null && ind.isInLibraryClasses(file.getVirtualFile())) {
- if (!name.equals("print") && UnsupportedFeaturesUtil.BUILTINS.get(languageLevel).contains(name)) {
- len = appendLanguageLevel(message, len, languageLevel);
- }
- }
- }
- //else {
- // if (!name.equals("print") && UnsupportedFeaturesUtil.BUILTINS.get(languageLevel).contains(name)) {
- // len = appendLanguageLevel(message, len, languageLevel);
- // }
- //}
- }
- }
- commonRegisterProblem(message, " not have method " + node.getCallee().getText(),
- len, node, null, false);
}
protected abstract void registerProblem(PsiElement node, String s, LocalQuickFix localQuickFix, boolean asError);
@@ -480,7 +448,7 @@ public abstract class CompatibilityVisitor extends PyAnnotator {
registerProblem(node, initMessage.toString(), localQuickFix, asError);
}
- private static int appendLanguageLevel(StringBuilder message, int len, LanguageLevel languageLevel) {
+ protected static int appendLanguageLevel(StringBuilder message, int len, LanguageLevel languageLevel) {
if (len != 0)
message.append(", ");
message.append(languageLevel.toString());
diff --git a/python/testData/inspections/PyCompatibilityInspection/callExpression.py b/python/testData/inspections/PyCompatibilityInspection/callExpression.py
index 1016d41d1e07..c17972dcde6c 100644
--- a/python/testData/inspections/PyCompatibilityInspection/callExpression.py
+++ b/python/testData/inspections/PyCompatibilityInspection/callExpression.py
@@ -3,9 +3,7 @@ class A(B):
super()
cmp()
-reduce()
+reduce()
all()
-bytearray()
-next()
-buffer()
\ No newline at end of file
+buffer()
\ No newline at end of file
diff --git a/python/testData/inspections/PyCompatibilityInspection/importElement.py b/python/testData/inspections/PyCompatibilityInspection/importElement.py
index 18c1a0c38885..18044ba73ab9 100644
--- a/python/testData/inspections/PyCompatibilityInspection/importElement.py
+++ b/python/testData/inspections/PyCompatibilityInspection/importElement.py
@@ -1 +1 @@
-import Bastion
\ No newline at end of file
+import Bastion
\ No newline at end of file
diff --git a/python/testData/inspections/PyCompatibilityInspection/test.py b/python/testData/inspections/PyCompatibilityInspection/test.py
index 8402810da88a..fce8c07725c7 100644
--- a/python/testData/inspections/PyCompatibilityInspection/test.py
+++ b/python/testData/inspections/PyCompatibilityInspection/test.py
@@ -37,8 +37,8 @@ a.cmp()
reduce()
all()
-bytearray()
-next()
+bytearray()
+next()
buffer()
########################
@@ -61,7 +61,7 @@ var = Bastion
+import Bastion
var = Bastion.BastionClass()
########################