コード例 #1
0
 @Nullable
 private PyType createCoroutineType(@Nullable PyType returnType) {
   final PyBuiltinCache cache = PyBuiltinCache.getInstance(this);
   if (returnType instanceof PyClassLikeType
       && PyNames.FAKE_COROUTINE.equals(((PyClassLikeType) returnType).getClassQName())) {
     return returnType;
   }
   final PyClass generator = cache.getClass(PyNames.FAKE_COROUTINE);
   return generator != null
       ? new PyCollectionTypeImpl(generator, false, Collections.singletonList(returnType))
       : null;
 }
コード例 #2
0
 @NotNull
 private static List<PsiElement> tryResolving(
     @NotNull PyExpression expression, @NotNull TypeEvalContext context) {
   final List<PsiElement> elements = Lists.newArrayList();
   if (expression instanceof PyReferenceExpression) {
     final PyReferenceExpression referenceExpr = (PyReferenceExpression) expression;
     final PyResolveContext resolveContext =
         PyResolveContext.noImplicits().withTypeEvalContext(context);
     final PsiPolyVariantReference reference = referenceExpr.getReference(resolveContext);
     final List<PsiElement> resolved = PyUtil.multiResolveTopPriority(reference);
     for (PsiElement element : resolved) {
       if (element instanceof PyFunction) {
         final PyFunction function = (PyFunction) element;
         if (PyUtil.isInit(function)) {
           final PyClass cls = function.getContainingClass();
           if (cls != null) {
             elements.add(cls);
             continue;
           }
         }
       } else if (element instanceof PyTargetExpression) {
         final PyTargetExpression targetExpr = (PyTargetExpression) element;
         // XXX: Requires switching from stub to AST
         final PyExpression assignedValue = targetExpr.findAssignedValue();
         if (assignedValue != null) {
           elements.add(assignedValue);
           continue;
         }
       }
       if (element != null) {
         elements.add(element);
       }
     }
   }
   return !elements.isEmpty() ? elements : Collections.singletonList(expression);
 }