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

fix: add extension name before loading in callbacks #1680

Merged
merged 1 commit into from
May 19, 2024

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

This one's on me - I probably should have done more testing.

Anyways, while making #1678, I did not account for, when adding prefixed commands in extensions, that the extension's extension_name does not exist yet. This variable is used when registering prefixed commands, and so an error appears:

Traceback (most recent call last):
  File "/home/astrea/Documents/dis-snek-testing-ground/interactions-py-library/interactions/client/client.py", line 1995, in __load_module
    setup(self, **load_kwargs)
  File "/home/astrea/Documents/dis-snek-testing-ground/bot/ipy5ext.py", line 10, in setup
    AExt(bot)
  File "/home/astrea/Documents/dis-snek-testing-ground/interactions-py-library/interactions/models/internal/extension.py", line 109, in __new__
    bot.add_command(val)
  File "/home/astrea/Documents/dis-snek-testing-ground/interactions-py-library/interactions/client/client.py", line 1422, in add_command
    hook(func)
  File "/home/astrea/Documents/dis-snek-testing-ground/interactions-py-library/interactions/ext/prefixed_commands/manager.py", line 237, in _register_command
    self.add_command(callback)
  File "/home/astrea/Documents/dis-snek-testing-ground/interactions-py-library/interactions/ext/prefixed_commands/manager.py", line 138, in add_command
    self._ext_command_list[command.extension.extension_name].add(command.name)
AttributeError: 'AExt' object has no attribute 'extension_name'. Did you mean: 'extension_error'?

I... don't know how prefixed command registering before #1678 worked, since the old version still should register prefixed commands before extension_name exists, but async funkiness, I suppose. Regardless, this PR fixes extension_name not existing by adding it in earlier.

Changes

  • Move extension_name assignment to before adding callbacks, instead of after.

Related Issues

Test Scenarios

import interactions as ipy
from interactions.ext.prefixed_commands import prefixed_command, PrefixedContext


class AExt(ipy.Extension):
    @prefixed_command()
    async def test2(self, ctx: PrefixedContext):
        await ctx.send("Woo!")


def setup(bot):
    AExt(bot)

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 changed the title fix: add extension name before loading in cmds fix: add extension name before loading in callbacks May 8, 2024
Copy link
Member

@silasary silasary left a comment

Choose a reason for hiding this comment

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

Seems reasonable

AstreaTSS added a commit to AstreaTSS/RealmsPlayerlistBot that referenced this pull request May 8, 2024
@silasary silasary merged commit 2f570a2 into interactions-py:unstable May 19, 2024
2 checks passed
AstreaTSS added a commit to AstreaTSS/RealmsPlayerlistBot that referenced this pull request May 20, 2024
AstreaTSS added a commit to AstreaTSS/RealmsPlayerlistBot that referenced this pull request May 20, 2024
@AstreaTSS AstreaTSS deleted the extension-name-fix branch May 30, 2024 19:49
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.

None yet

2 participants