List<PsiElement> (@NotNull PyReferenceExpression expression, @NotNull TypeEvalContext context) { final QualifiedName qualifiedName = expression.asQualifiedName(); final PyFile pyFile = as(FileContextUtil.getContextFile(expression), PyFile.class); PsiElement anchor = expression.getContainingFile().getUserData(FRAGMENT_OWNER); ScopeOwner scopeOwner; if (anchor == null) { scopeOwner = pyFile; } else if (anchor instanceof ScopeOwner anchorAsScope) { scopeOwner = anchorAsScope; } else { scopeOwner = ScopeUtil.getScopeOwner(anchor); } if (scopeOwner != null && qualifiedName != null) { List<PsiElement> results = new ArrayList<>(); while (scopeOwner != null) { results.addAll(PyResolveUtil.resolveQualifiedNameInScope(qualifiedName, scopeOwner, context)); scopeOwner = ScopeUtil.getScopeOwner(scopeOwner); } return results; } return Collections.singletonList(expression); }