PsiComment () { PsiComment comment = null; final PyAssignmentStatement assignment = PsiTreeUtil.getParentOfType(this, PyAssignmentStatement.class); if (assignment != null) { final PyExpression assignedValue = assignment.getAssignedValue(); if (assignedValue != null && !PsiTreeUtil.isAncestor(assignedValue, this, false)) { comment = as(PyPsiUtils.getNextNonWhitespaceSiblingOnSameLine(assignedValue), PsiComment.class); } } else { PyStatementListContainer forOrWith = null; final PyForPart forPart = PsiTreeUtil.getParentOfType(this, PyForPart.class); if (forPart != null && PsiTreeUtil.isAncestor(forPart.getTarget(), this, false)) { forOrWith = forPart; } final PyWithItem withPart = PsiTreeUtil.getParentOfType(this, PyWithItem.class); if (withPart != null && PsiTreeUtil.isAncestor(withPart.getTarget(), this, false)) { forOrWith = as(withPart.getParent(), PyWithStatement.class); } if (forOrWith != null) { comment = PyUtil.getCommentOnHeaderLine(forOrWith); } } return comment != null && PyTypingTypeProvider.getTypeCommentValue(comment.getText()) != null ? comment : null; }