@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;
 }
Ejemplo n.º 3
0
 @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;
 }
 @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);
         }
       }
     }
   }
 }