diff --git a/python/src/com/jetbrains/python/inspections/PySetFunctionToLiteralInspection.java b/python/src/com/jetbrains/python/inspections/PySetFunctionToLiteralInspection.java index 2a884d22afab..2a563fe9cfcb 100644 --- a/python/src/com/jetbrains/python/inspections/PySetFunctionToLiteralInspection.java +++ b/python/src/com/jetbrains/python/inspections/PySetFunctionToLiteralInspection.java @@ -1,7 +1,12 @@ package com.jetbrains.python.inspections; +import com.intellij.codeInspection.InspectionProfile; +import com.intellij.codeInspection.InspectionProfileEntry; import com.intellij.codeInspection.LocalInspectionToolSession; import com.intellij.codeInspection.ProblemsHolder; +import com.intellij.codeInspection.ex.InspectionToolWrapper; +import com.intellij.openapi.util.JDOMExternalizableStringList; +import com.intellij.profile.codeInspection.InspectionProjectProfileManager; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiElementVisitor; import com.intellij.psi.PsiReference; @@ -44,18 +49,32 @@ public class PySetFunctionToLiteralInspection extends PyInspection { @Override public void visitPyCallExpression(final PyCallExpression node) { - if (LanguageLevel.forElement(node).supportsSetLiterals()) { - PyExpression callee = node.getCallee(); - if (node.isCalleeText(PyNames.SET) && isInBuiltins(callee)) { - PyExpression[] arguments = node.getArguments(); - if (arguments.length == 1) { - PyElement[] elements = getSetCallArguments(node); - if (elements.length != 0) - registerProblem(node, PyBundle.message("INSP.NAME.set.function.to.literal"), - new ReplaceFunctionWithSetLiteralQuickFix()); + if (!isAvailable(node)) return; + PyExpression callee = node.getCallee(); + if (node.isCalleeText(PyNames.SET) && isInBuiltins(callee)) { + PyExpression[] arguments = node.getArguments(); + if (arguments.length == 1) { + PyElement[] elements = getSetCallArguments(node); + if (elements.length != 0) + registerProblem(node, PyBundle.message("INSP.NAME.set.function.to.literal"), + new ReplaceFunctionWithSetLiteralQuickFix()); + } + } + } + + private static boolean isAvailable(PyCallExpression node) { + final InspectionProfile profile = InspectionProjectProfileManager.getInstance(node.getProject()).getInspectionProfile(); + final InspectionToolWrapper inspectionTool = profile.getInspectionTool("PyCompatibilityInspection", node.getProject()); + if (inspectionTool != null) { + final InspectionProfileEntry inspection = inspectionTool.getTool(); + if (inspection instanceof PyCompatibilityInspection) { + final JDOMExternalizableStringList versions = ((PyCompatibilityInspection)inspection).ourVersions; + for (String s : versions) { + if (!LanguageLevel.fromPythonVersion(s).supportsSetLiterals()) return false; } } } + return LanguageLevel.forElement(node).supportsSetLiterals(); } private static boolean isInBuiltins(PyExpression callee) {