@NotNull private static List<RatedResolveResult> resolveInPackageModule( @NotNull PyFile parent, @NotNull String referencedName, @Nullable PsiFile containingFile, boolean fileOnly, boolean checkForPackage) { final List<RatedResolveResult> moduleMembers = resolveModuleMember(parent, referencedName); final List<RatedResolveResult> resolvedInModule = Lists.newArrayList(); final List<RatedResolveResult> results = Lists.newArrayList(); for (RatedResolveResult member : moduleMembers) { final PsiElement moduleMember = member.getElement(); if (!fileOnly || PyUtil.instanceOf(moduleMember, PsiFile.class, PsiDirectory.class)) { results.add(member); if (moduleMember != null && !preferResolveInDirectoryOverModule(moduleMember)) { resolvedInModule.add(member); } } } if (!resolvedInModule.isEmpty()) { return resolvedInModule; } final List<RatedResolveResult> resolvedInDirectory = resolveInPackageDirectory( parent, referencedName, containingFile, fileOnly, checkForPackage); if (!resolvedInDirectory.isEmpty()) { return resolvedInDirectory; } return results; }
private static boolean preferResolveInDirectoryOverModule(@NotNull PsiElement resolved) { return PsiTreeUtil.getStubOrPsiParentOfType(resolved, PyExceptPart.class) != null || PyUtil.instanceOf(resolved, PsiFile.class, PsiDirectory.class) || // XXX: Workaround for PY-9439 isDunderAll(resolved); }