Ref<PyType> (@NotNull PsiElement resolved, @NotNull PyExpression typeHint, @NotNull Context context) { if (resolved instanceof PyQualifiedNameOwner && (SELF.equals(((PyQualifiedNameOwner)resolved).getQualifiedName()) || SELF_EXT.equals(((PyQualifiedNameOwner)resolved).getQualifiedName()))) { PsiElement typeHintContext = getStubRetainedTypeHintContext(typeHint); PyClass containingClass = typeHintContext instanceof PyClass ? (PyClass)typeHintContext : PsiTreeUtil.getStubOrPsiParentOfType(typeHintContext, PyClass.class); if (containingClass == null) return null; PyClassType scopeClassType = as(containingClass.getType(context.getTypeContext()), PyClassType.class); if (scopeClassType == null) return null; return Ref.create(new PySelfType(scopeClassType)); } return null; }