-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
[v3 cog manager, utils] handle missing cogs correctly, add some helpful algorithms #1989
[v3 cog manager, utils] handle missing cogs correctly, add some helpful algorithms #1989
Conversation
075d7ed
to
e81d875
Compare
e81d875
to
100f0e5
Compare
100f0e5
to
45450c8
Compare
For cog loading, only show "cog not found" if the module in question was the one that failed to import. ImportErrors within cogs will show an error as they should. - deduplicator, benchmarked to be the fastest - bounded gather and bounded async as_completed - tests for all additions
45450c8
to
3e47dcb
Compare
@Tobotimus rebased. |
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.
@calebj This PR adds a lot of really nice things, thank you. Just a few little things that can be fixed up and then I think it's good to go.
redbot/core/utils/__init__.py
Outdated
loop = asyncio.get_event_loop() | ||
|
||
if semaphore is None: | ||
if type(limit) != int or limit <= 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.
Please use not isinstance
instead of type() !=
redbot/core/utils/__init__.py
Outdated
try: | ||
done, pending = await asyncio.wait(pending, loop=loop, return_when=FIRST_COMPLETED) | ||
except asyncio.CancelledError: | ||
[] |
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.
Not sure what's going on with this []
statement, would prefer the use of pass
or contextlib.supress
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 think I had logic here for cancelling pending tasks, but I found something better (see the push)
redbot/core/utils/__init__.py
Outdated
|
||
async def sem_wrapper(sem, task): | ||
async with sem: | ||
return await task |
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.
Since this sem_wrapper
is common to the one in bounded_gather_iter
, it can be moved to the module-level and made private
redbot/core/utils/__init__.py
Outdated
loop = asyncio.get_event_loop() | ||
|
||
if semaphore is None: | ||
if type(limit) != int or limit <= 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.
isinstance
here too
redbot/core/core_commands.py
Outdated
@@ -23,6 +23,7 @@ | |||
from redbot.core import checks | |||
from redbot.core import i18n | |||
from redbot.core import commands | |||
from redbot.core.cog_manager import NoSuchCog |
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.
Unused import
redbot/core/cog_manager.py
Outdated
""" | ||
resolved_paths = _deduplicate(await self.paths()) | ||
resolved_paths = deduplicate_iterables(await self.paths()) |
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.
paths()
already deduplicates the paths before it returns, so you can remove the call to deduplicate here
So I went source diving and realized as_completed works the way I want it to, and I don't need to reinvent the wheel for cancelling tasks that remain if the generator is `break`ed out of. So there's that.
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'm not seeing any issues with this after the changes made. I'm giving it a 👍
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.
Awesome. Thanks @calebj and thanks @mikeshardmind for reviewing
Type
Description of the changes
For cog loading, only show "cog not found" if the module in question was the one that failed to import.
ImportErrors
within cogs will now show an error as they should.Also:
asyncio.gather
and an asyncas_completed