discord.py icon indicating copy to clipboard operation
discord.py copied to clipboard

Try Disallowing Shadowing at Compile Time in Cogs

Open Rapptz opened this issue 5 years ago • 11 comments

I'm thinking of disallowing shadowing with a more descriptive error at compile time for the cog. One thing I worry about is "legitimate" use cases. I could not think of any. I'm tracking this issue to receive comments on whether this should a compile time error the library does to save some support time.

Example of what would be disallowed:

class C(commands.Cog):
    @commands.command()
    async def foo(self, ctx):
        pass

    @commands.command()
    async def foo(self, ctx):
        pass

Rapptz avatar May 03 '19 10:05 Rapptz

Considering that the name keyword argument for the @commands.command() decorator exists, i don't think that there are many valid uses

gamescom15 avatar May 03 '19 10:05 gamescom15

Sounds like a no brainer that would probably save headaches on both sides.

paris-ci avatar May 03 '19 13:05 paris-ci

I would be curious if anyone could come up with a valid use-case for this. Definitely should raise at compile-time

JosephFKnight avatar May 06 '19 13:05 JosephFKnight

As long as this only prevents shadowing commands (and not functions) this won't be a large issue.

With the prevention of shadowing all functions in a class built into this, you could break uses of typing.overload needlessly.

mikeshardmind avatar Jun 23 '19 05:06 mikeshardmind

What happens if you subclass a cog and use ctx.invoke(super().command, ...) or super().command.callback(ctx, ...) to extend one of the commands?

ioistired avatar Jun 24 '19 01:06 ioistired

Nothing?

Rapptz avatar Jun 24 '19 01:06 Rapptz

OK. And if this is a breaking change, why is it being considered?

ioistired avatar Jun 24 '19 05:06 ioistired

It's not

Le lun. 24 juin 2019 à 07:45, Ben Mintz [email protected] a écrit :

OK. And if this is a breaking change, why is it being considered?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Rapptz/discord.py/issues/2134?email_source=notifications&email_token=AAXL4HGBLUKQNXBR3EBS7N3P4BNPXA5CNFSM4HKS3CTKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODYL2LSY#issuecomment-504866251, or mute the thread https://github.com/notifications/unsubscribe-auth/AAXL4HC32WLN6KDKMTNSWFDP4BNPXANCNFSM4HKS3CTA .

paris-ci avatar Jun 24 '19 05:06 paris-ci

It's labeled as such. And this breaks the behavior of a cog which shadows a command name.

ioistired avatar Jun 24 '19 05:06 ioistired

@bmintz an issue brought up every once and a while is having a function name foo spread between 2 different command groups. Having an error would make it more obvious to the developer.

LucasCoderT avatar Jun 24 '19 13:06 LucasCoderT

It's more of a bug fix than a breaking change. Shadowed commands have never worked.

Rapptz avatar Jun 24 '19 15:06 Rapptz