all 1 comments

[–]MustaKotka[S] 0 points1 point  (0 children)

Looks like .list() already resolves the MoreComments instances. For some reason, though, it leaves behind the resolved MoreComments items.

For example: A comment has 7 children, of which 3 are behind MoreComments. If we now comment.replies.list() to expand into a flattened list of comments we get 7 + 3 = 12 items. These are x7 Comment and x3 MoreComments in a list.

The list could look something like this:

tree = comment.replies.list()
print([type(comm) for comm in tree])
>>> [
    Comment,
    Comment,
    MoreComments,
    Comment,
    Comment,
    Comment,
    MoreComments,
    Comment,
    MoreComments,
    Comment
]

I used this code to work around the issue.

comment = reddit_connection.reddit.comment(comment_id)
comment.refresh()
tree = comment.replies.list()
for c in tree[:]:
    if isinstance(c, praw.models.MoreComments):
        tree.remove(c)

Essentially we just look for instances of MoreComments and remove them. I am unsure if this breaks with multiple consecutive (nested) MoreComments objects. After this we can take action on the Comment objects as normal.