Collection<PyClass> (Collection<PyClass> classes, PsiFile containingFile) { if (classes.size() <= 1) { return classes; } List<PyClass> result = new ArrayList<>(); for (PyClass pyClass : classes) { if (pyClass.getContainingFile() == containingFile) { result.add(pyClass); } else { final PsiElement exportedClass = ((PyFile)containingFile).getElementNamed(pyClass.getName()); if (exportedClass == pyClass) { result.add(pyClass); } } } return result; }