Skip to content
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

[Commands] Refactor command and group decorators #1818

Merged

Conversation

Tobotimus
Copy link
Member

Curiously, these decorators were previously placed in the Command class. Whilst it hadn't caused any issues yet, there's no reason for them to be there. This puts them in a new overridden GroupMixin class, so that the bot also inherits these decorators.

I also added some tests as a sanity check, and also to make sure this shit doesn't break in the future.

@Tobotimus Tobotimus added the V3 label Jun 7, 2018
@Tobotimus Tobotimus requested a review from tekulvw June 7, 2018 14:31
@Tobotimus Tobotimus requested a review from Twentysix26 as a code owner June 7, 2018 14:31
Tobotimus added 3 commits June 9, 2018 11:21
…factor_cmd_decorators

# Conflicts:
#	redbot/core/bot.py
…factor_cmd_decorators

# Conflicts:
#	redbot/core/commands/commands.py
@@ -24,7 +22,7 @@
from .sentry import SentryManager


class RedBase(BotBase, RPCMixin):
class RedBase(commands.GroupMixin, commands.bot.BotBase, RPCMixin):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why call our own reference to BotBase? I don't see a whole lot of sense in doing this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can change it to discord.ext.commands.bot.BotBase if you'd like, it wouldn't make a difference

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could instead subclass discord.ext.commands.bot.BotBase and add the GroupMixin there. It wouldn't be any different to the current setup but would simplify RedBase's direct inheritance

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See here for an example of what I mean, I don't really think its necessary but all of this inheritance stuff is pretty confusing to some, perhaps this makes it a bit simpler? I'm not sure.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, this is probably a better way to show the example

@palmtree5 palmtree5 added this to the Beta 17 milestone Jun 10, 2018
@Kowlin
Copy link
Member

Kowlin commented Jul 11, 2018

Due to my inexperience I'm not gonna touch this in Beta 17. Todo for Beta 18

Copy link
Contributor

@mikeshardmind mikeshardmind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything in the bot appears to be fine with these changes, but I do think a tweak to the mro here should be made.

Here's the mro for commands.group:

(<class 'redbot.core.commands.commands.Group'>, 
<class 'redbot.core.commands.commands.Command'>,
 <class 'redbot.core.commands.commands.GroupMixin'>, 

<class 'discord.ext.commands.core.Group'>,
<class 'discord.ext.commands.core.GroupMixin'>,
<class 'discord.ext.commands.core.Command'>,

<class 'object'>)

I'm very hesitant to have our explicit overrides have a different ordering here than discord.py's bases without extremely good reason for doing so, and that reason being documented for future maintaining. While it doesn't seem to matter currently, it seems a recipe for potential subtle, hard to debug breakage later.

@calebj
Copy link
Member

calebj commented Aug 10, 2018

@Tobotimus
Copy link
Member Author

Thanks @calebj and @mikeshardmind, I've tweaked the MRO accordingly

Copy link
Member

@calebj calebj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't noticed any issues so far while running this. Approving now that the MRO fix has been applied.

@Tobotimus Tobotimus added the QA: Passed Used by few QA members. Has been approved by the assigned QA member(s). label Aug 13, 2018
@Tobotimus Tobotimus changed the title [V3 Commands] Refactor command and group decorators [Commands] Refactor command and group decorators Aug 25, 2018
@Tobotimus Tobotimus merged commit 48a7a21 into Cog-Creators:V3/develop Aug 26, 2018
@Tobotimus Tobotimus deleted the V3/refactor_cmd_decorators branch August 26, 2018 13:25
@Jackenmen Jackenmen added the Type: Bug Unexpected behavior, result, or exception. In case of PRs, it is a fix for the foregoing. label Jul 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
QA: Passed Used by few QA members. Has been approved by the assigned QA member(s). Type: Bug Unexpected behavior, result, or exception. In case of PRs, it is a fix for the foregoing.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants