@NotNull
 private static List<RatedResolveResult> resolveInPackageDirectory(
     @Nullable PsiElement parent,
     @NotNull String referencedName,
     @Nullable PsiFile containingFile,
     boolean fileOnly,
     boolean checkForPackage) {
   final PsiElement parentDir = PyUtil.turnInitIntoDir(parent);
   if (parentDir instanceof PsiDirectory) {
     final List<RatedResolveResult> resolved =
         resolveInDirectory(
             referencedName, containingFile, (PsiDirectory) parentDir, fileOnly, checkForPackage);
     if (!resolved.isEmpty()) {
       for (RatedResolveResult result : resolved) {
         if (result.getRate() > RatedResolveResult.RATE_LOW) {
           return resolved;
         }
       }
     }
     if (parent instanceof PsiFile) {
       final PsiElement foreign = resolveForeignImports((PsiFile) parent, referencedName);
       if (foreign != null) {
         final ResolveResultList results = new ResolveResultList();
         results.addAll(resolved);
         results.poke(foreign, RatedResolveResult.RATE_NORMAL);
         return results;
       }
     }
     return resolved;
   }
   return Collections.emptyList();
 }
 public static ResolveResultList rateResults(List<? extends PsiElement> targets) {
   ResolveResultList ret = new ResolveResultList();
   for (PsiElement target : targets) {
     if (target instanceof PsiDirectory) {
       target = PyUtil.getPackageElement((PsiDirectory) target, null);
     }
     if (target != null) {
       int rate = RatedResolveResult.RATE_HIGH;
       if (target instanceof PyFile) {
         for (PyResolveResultRater rater :
             Extensions.getExtensions(PyResolveResultRater.EP_NAME)) {
           rate += rater.getImportElementRate(target);
         }
       } else if (isDunderAll(target)) {
         rate = RatedResolveResult.RATE_NORMAL;
       }
       ret.poke(target, rate);
     }
   }
   return ret;
 }