-
-
Notifications
You must be signed in to change notification settings - Fork 453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initialise .replies
to an empty list
#1103
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I don't really like about this approach, however, is that accessing comment.replies
no longer triggers a fetch, as I believe it did before. Actually, it doesn't appear that it does it currently, but I think PRAW used to have that as intended behavior.
with self.recorder.use_cassette("TestComment.test_refresh"): | ||
comment = Comment(self.reddit, "d81vwef").refresh() | ||
assert len(comment.replies) > 0 | ||
assert len(comment.replies) == 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assertion can be outside of the cassette, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this trigger a fetch? And if it does, it's the wrong value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The .replies
property calls .submission
which in turn calls _extract_submission_id()
which triggers a fetch because link_id
is read.
And if it does, it's the wrong value.
I’m not sure what you mean by this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignore my previous comment. I looked at the documentation in PRAW 3.6 and it reads:
If the comment is not from a submission, :meth:
replies
will always be an empty list unless you call :meth:refresh() before calling :meth:
replies` due to a limitation in reddit's API.
It’s actually the other way around. It now a fetches when it didn’t before. I deem this correct behaviour though since all other non underscore attributes trigger a fetch. Anyhow, the difference doesn’t really matter since if one wants to actually get replies from |
The
Comment.replies
attribute begins asNone
and transitions to an empty list after a fetch. The fetch doesn’t retrieve the comment’s replies, retrieving replies is what.refresh()
is for hence the transition to a list can be confusing.This PR makes it so that
.replies
is initialised as an empty list so that its value doesn’t change after a fetch. I’ve chosen an empty list instead ofNone
so that its type is consistent.