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

fix: fail loudly if extension classes are named the same

Open AstreaTSS opened this issue 1 year ago • 0 comments

Pull Request Type

  • [ ] Feature addition
  • [x] Bugfix
  • [ ] Documentation update
  • [ ] Code refactor
  • [ ] Tests improvement
  • [ ] CI/CD pipeline enhancement
  • [ ] Other: [Replace with a description]

Description

Currently, loading two extensions that have the same class name causes subtle bugs to occur, which eventually culminates in reload_extension and other parts of code to error out in a confusing way (it literally took a whole year of discussion in the help forums to find this, as a refernece). While interactions.py should be able to handle extensions like this, making that work would require breaking changes, so failing loudly is a preferable solution here.

This PR does just that.

Changes

  • Error out when initializing an extension if another extension has the same class name.

Related Issues

Test Scenarios

# main.py
bot.load_extension("extension_1")
bot.load_extension("extension_2")
bot.reload_extension("extension_1")
# extension_1.py

from interactions import Extension, slash_command, SlashContext

class MyExtension(Extension):
    @slash_command()
    async def test(ctx: SlashContext):
        await ctx.send("Hello!")
# extension_2.py

from interactions import Extension, slash_command, SlashContext

class MyExtension(Extension):
    @slash_command()
    async def test2(ctx: SlashContext):
        await ctx.send("Hello!")

Python Compatibility

  • [ ] I've ensured my code works on Python 3.10.x
  • [x] I've ensured my code works on Python 3.11.x

Checklist

  • [x] I've run the pre-commit code linter over all edited files
  • [x] I've tested my changes on supported Python versions
  • [ ] I've added tests for my code, if applicable
  • [ ] I've updated / added documentation, where applicable

AstreaTSS avatar Feb 21 '24 23:02 AstreaTSS