Skip to content

fix: fail loudly if extension classes are named the same #1618

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

Merged

Conversation

AstreaTSS
Copy link
Member

Pull Request Type

  • Feature addition
  • 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
  • I've ensured my code works on Python 3.11.x

Checklist

  • I've run the pre-commit code linter over all edited files
  • 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 AstreaTSS merged commit 7fdcef2 into interactions-py:unstable Mar 8, 2024
@AstreaTSS AstreaTSS deleted the extension-class-name-error branch March 8, 2024 05:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants