-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Return new instance in Poll.end to avoid inconsistencies #10056
base: master
Are you sure you want to change the base?
Conversation
self._message = await self._message.end_poll() | ||
|
||
return self | ||
message = await self._message.end_poll() |
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.
._message still needs to be set, plus, you can simply do self._update(message) to update the data
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.
Ah, I went with this way intentionally because I wasn’t sure if the update should even be in-place. I’ll change it to make sure everything is done to the current instance.
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.
You could change the _update behaviour to update the current poll vote count and such, though
discord/poll.py
Outdated
@@ -547,7 +547,7 @@ def get_answer( | |||
|
|||
return self._answers.get(id) | |||
|
|||
async def end(self) -> Self: | |||
async def end(self) -> Poll: |
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 is typed likeSelf
for subclasses
Summary
Currently, the
Poll.end
method updates thePoll.message
attribute with the response from the API call, but still returns the current instance. This can causePoll.message
to be newer than the rest of the data stored inPoll
. This also means that the the instance is being updated in-place regardless of whether it is from the state, which I can't find an intentional reason for. Both of these seem inconsistent with usual library behavior.The following example shows this behavior:
This PR changes the behavior to instead return the poll created from the API call inside
Poll.end
. This means that making an API call will not modify the instance used to make it, instead returning a fresh one, with more updated and consistent data.Checklist