question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MoreComments.comments() return value

See original GitHub issue

I’ve noticed an inconsistency in the way that MoreComments.comments() are being returned. Not sure if this is intended behavior or not, but I’ve found it very difficult to work around.

Here’s an example:

reddit = praw.Reddit(user_agent='reddit terminal viewer v0.0')
submission = reddit.get_submission('http://www.reddit.com/r/CollegeBasketball/comments/31owr1/game_thread_ncaa_national_championship_wisconsin/')
for comment in submission.comments:
    if isinstance(comment, praw.objects.MoreComments):
        print('MoreComments')
    else:
        print(comment._replies)

returns something like this

[<praw.objects.Comment object at 0x7f63d2b1a9e8>, <praw.objects.MoreComments object at 0x7f63d2b1aac8>]
[<praw.objects.Comment object at 0x7f63d2b1ada0>, <praw.objects.MoreComments object at 0x7f63d2b1aeb8>]
[<praw.objects.Comment object at 0x7f63d2b25080>, <praw.objects.MoreComments object at 0x7f63d2b252b0>]
[<praw.objects.MoreComments object at 0x7f63d2b25438>]
[<praw.objects.Comment object at 0x7f63d2b25668>, <praw.objects.MoreComments object at 0x7f63d2b25828>]
[]
[<praw.objects.Comment object at 0x7f63d2b25ac8>, <praw.objects.MoreComments object at 0x7f63d2b25dd8>]
[<praw.objects.Comment object at 0x7f63d227a048>]
[<praw.objects.MoreComments object at 0x7f63d227a588>]
[]
[<praw.objects.MoreComments object at 0x7f63d227a8d0>]

However, doing the same loop over for comment in more_comments_object.comments(update=True) returns

None
MoreComments
[]
None
MoreComments
None
MoreComments
None
MoreComments
[]
[]
[]

It looks like in the second case the MoreComments aren’t getting attached the their parent’s replies. All of the None values should actually be [MoreComments]. E.g.

[MoreComments]
[]
[MoreComments]
[MoreComments]
[MoreComments]
[]
[]
[]

As a result, trying to build a comment tree by flattening each comment.replies inserts duplicate replies into the tree and makes a bunch of unnecessary calls to api/comments/id instead of /api/morechildren.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
michael-lazarcommented, Nov 14, 2016

Here’s what I did in case anyone else comes across this issue. Note that I had to use hasattr(comment, 'replies') instead of comment.replies to avoid the hidden http call. https://github.com/michael-lazar/rtv/blob/58f58f816736b18cd2985c39e38b052cd663e645/rtv/content.py#L49

0reactions
bboecommented, Nov 14, 2016

@michael-lazar I thought about modifying the return value for the More objects to return a forest rather than a flat list. However, I’d prefer to keep the structure of the return similar to how Reddit returns the values. You should be able to build any such tree in your own code.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Comment Extraction and Parsing — PRAW 7.3.0 documentation
These objects represent the “load more comments”, and “continue this ... list() , which returns a list of comments traversed in the same...
Read more >
Should a method comment include both a summary and return ...
Now, I don't really want to know what the method does, but I do want to know something more about the return value....
Read more >
Comments - The Modern JavaScript Tutorial
There's a special syntax JSDoc to document a function: usage, parameters, returned value. For instance:.
Read more >
Best practices for writing code comments - Stack Overflow Blog
Comments that add no information have negative value because they: add visual clutter; take time to write and read; can become out-of-date. The ......
Read more >
Where is the syntax for TypeScript comments documented?
Focus on the types (not the content). JSDoc version (notice types in docs): /** * Returns the sum of a and b *...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found