-
Notifications
You must be signed in to change notification settings - Fork 41
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
2.0.2 update #117
2.0.2 update #117
Conversation
…ers to close the client connection from within a async function such as async main(). This is useful to allow users to use the `asyncio.run()` wrapper properly
…g to grab a dictionary of members in the clan but that kwards was not available. I added ```py @cached_property("_cs_members_dict") def members_dict(self) -> typing.Dict[str, ClanMember]: """Dict[str, :class:`ClanMember`]: A dict of members that belong to the clan.""" return {m.tag: m for m in self._iter_members ``` To clans to have the attribute available for the player iterator
2.0.2 clan castle update
… the session created was only closed when there was a successful interaction with the API. If there is a failure with logging in, for example, the session would not be closed. The fix used is wrapping the body with a session context manager to automatically cleanup after itself.
…self by closing the session
…self by closing the session
…t to properly invoke a command context and from the forums it is not recommended to do so
…asyncio.run wrapper (recommended by asycion) and added a cogs example
…tion methods that coc.EventsClient has isntead of the lists
… method for closing the session created
…perly closes the connection when it is done
…GitHub Action to fail since the even loop was not gracefully closed
… the recommended asycsio.run(). Removing them from supported versions
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.
Great, thanks! Most of my comments are just musings, feel free to reply to as much or little as you want, although most of it looks good to go.
Should probably add to the changelog, too. It's in docs/misc/changelog I think
coc/client.py
Outdated
except Exception as error: | ||
LOG.error("Invalid credentials\n%s", error) | ||
await http.close() | ||
raise |
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.
Does this re-raise the InvalidCredentials error? For people who don't have logging setup a detailed exception is important because it's ambiguous why it failed otherwise
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.
Yeah it re-raises coc.InvalidCredentials so the user should already be tracking. You can see it in action in the examples
self.dispatch("on_client_close") | ||
self.loop.run_until_complete(self.http.close()) | ||
self.loop.close() | ||
async def close(self) -> None: |
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.
Idk if anyone used it but should this still dispatch that on_client_close
event?
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.
I tried looking at the dispatch stuff but I don't really understand it. Could you provide some guidance on it?
…ead of client. Additionally, added a descriptive message to the exception class
…asyncio.loop, I went ahead and updated the coc.login to be async and changed all the examples to use it.
setup.py in the main directory also needs the version tag changed to v2.1.0 |
Ready for review, please. Combined #113 #116 #112 #115
Changes
discord_links.py
now supportsawait client.close()
client.py
no longer handles the creation and management of asyncio loops. Instead, it will just handle cleaning itself and allow wrappers such asasyncio.run
to do the cleaning.discord_cog
example to showcase how to create a bot that inherits from thediscord.exe.Bot
client.login
in a context manager to handle situations where the login failed. This allows cleanup of the session createdasyncio.run