PyFunction (@NotNull String redirect, @NotNull PsiElement reference) { final QualifiedName qualifiedName = QualifiedName.fromDottedString(redirect); final String functionName = qualifiedName.getLastComponent(); final List<PsiElement> items = PyResolveImportUtil.resolveQualifiedName(qualifiedName.removeLastComponent(), PyResolveImportUtil.fromFoothold(reference)); for (PsiElement item : items) { if (item instanceof PsiDirectory) { item = ((PsiDirectory)item).findFile(PyNames.INIT_DOT_PY); } if (item instanceof PyFile) { final PsiElement element = ((PyFile)item).getElementNamed(functionName); if (element instanceof PyFunction) { return (PyFunction)element; } } } return null; }