@Nullable
 private static PyGenericType getGenericType(
     @NotNull PsiElement element, @NotNull Context context) {
   if (element instanceof PyCallExpression) {
     final PyCallExpression assignedCall = (PyCallExpression) element;
     final PyExpression callee = assignedCall.getCallee();
     if (callee != null) {
       final Collection<String> calleeQNames =
           resolveToQualifiedNames(callee, context.getTypeContext());
       if (calleeQNames.contains("typing.TypeVar")) {
         final PyExpression[] arguments = assignedCall.getArguments();
         if (arguments.length > 0) {
           final PyExpression firstArgument = arguments[0];
           if (firstArgument instanceof PyStringLiteralExpression) {
             final String name = ((PyStringLiteralExpression) firstArgument).getStringValue();
             if (name != null) {
               return new PyGenericType(name, getGenericTypeBound(arguments, context));
             }
           }
         }
       }
     }
   }
   return null;
 }
 private static boolean isValidIntroduceVariant(PsiElement element) {
   final PyCallExpression call = PsiTreeUtil.getParentOfType(element, PyCallExpression.class);
   if (call != null && PsiTreeUtil.isAncestor(call.getCallee(), element, false)) {
     return false;
   }
   return true;
 }
 @Override
 public void visitPyCallExpression(final PyCallExpression node) {
   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 void addVariants(
      Document document,
      int line,
      @Nullable PsiElement element,
      List<PySmartStepIntoVariant> variants,
      Set<PyCallExpression> visited) {
    if (element == null) return;

    final PyCallExpression expression =
        PsiTreeUtil.getParentOfType(element, PyCallExpression.class);
    if (expression != null
        && expression.getTextRange().getEndOffset() <= document.getLineEndOffset(line)
        && visited.add(expression)) {
      addVariants(document, line, expression.getParent(), variants, visited);
      PyExpression ref = expression.getCallee();

      variants.add(new PySmartStepIntoVariant(ref));
    }
  }
 @Nullable
 public static String extractDeprecationMessage(List<PyStatement> statements) {
   for (PyStatement statement : statements) {
     if (statement instanceof PyExpressionStatement) {
       PyExpressionStatement expressionStatement = (PyExpressionStatement) statement;
       if (expressionStatement.getExpression() instanceof PyCallExpression) {
         PyCallExpression callExpression = (PyCallExpression) expressionStatement.getExpression();
         if (callExpression.isCalleeText(PyNames.WARN)) {
           PyReferenceExpression warningClass =
               callExpression.getArgument(1, PyReferenceExpression.class);
           if (warningClass != null
               && (PyNames.DEPRECATION_WARNING.equals(warningClass.getReferencedName())
                   || PyNames.PENDING_DEPRECATION_WARNING.equals(
                       warningClass.getReferencedName()))) {
             return PyPsiUtils.strValue(callExpression.getArguments()[0]);
           }
         }
       }
     }
   }
   return null;
 }
  public static PyElement[] getSetCallArguments(PyCallExpression node) {
    PyExpression argument = node.getArguments()[0];
    if (argument instanceof PyStringLiteralExpression) {
      return PyElement.EMPTY_ARRAY;
    }
    if ((argument instanceof PySequenceExpression
        || (argument instanceof PyParenthesizedExpression
            && ((PyParenthesizedExpression) argument).getContainedExpression()
                instanceof PyTupleExpression))) {

      if (argument instanceof PySequenceExpression)
        return ((PySequenceExpression) argument).getElements();
      PyExpression tuple = ((PyParenthesizedExpression) argument).getContainedExpression();
      if (tuple instanceof PyTupleExpression) return ((PyTupleExpression) (tuple)).getElements();
    }
    return PyElement.EMPTY_ARRAY;
  }
 @Override
 public void visitPyCallExpression(final PyCallExpression node) {
   // TODO: refactor, messy code
   final PyExpression callee = node.getCallee();
   if (callee != null) {
     final PsiReference calleeRef = callee.getReference();
     if (calleeRef != null) {
       final PsiElement calleeDeclaration = calleeRef.resolve();
       if (calleeDeclaration instanceof PyFunction) {
         final PyFunction calleeFunction = (PyFunction) calleeDeclaration;
         final PyClass clazz = calleeFunction.getContainingClass();
         if (clazz != null) {
           if (PyUtil.isInit(calleeFunction)) {
             return; // Init call should not be marked as dependency
           }
           myResult.putValue(clazz, calleeFunction);
         }
       }
     }
   }
 }