PsiElement (@NotNull PsiElement nodeAtCaret) { PsiElement wrappable = nodeAtCaret; while (true) { PsiElement next = PsiTreeUtil.getParentOfType(wrappable, PyEditorHandlerConfig.CLASSES_TO_PARENTHESISE_ON_ENTER); if (next == null) { break; } wrappable = next; } return wrappable != nodeAtCaret ? wrappable : null; }