Skip to content

Confusing error for typed func passed to bridge_command #1603

@ActuallyHappening

Description

@ActuallyHappening

Summary

Error raised when a typed function is used with the @bridge_command decorator should be fixed

Reproduction Steps

Recently, I have been using the bridge_command decorator to avoid code duplication and have struck upon an interesting error message being raised when I use from __future__ import annotations.

I have installed py-cord through pip install -U py-cord with python3 -c "import discord; print(f'{discord.__version__=}, {discord.__title__=}') returning "discord.version='2.1.1', discord.title='pycord'"

When I use functions with the future annotations, I seem to get a strange error on the line I defined the function:

Exception has occurred: AttributeError
'str' object has no attribute 'name'

Although this may not be a bug, not experienced enough with py-cord to know if such typing is an internal problem, the error itself gives no hints on its origin. In no way does it aid in identifying the type hints used as an issue, which is my main highlight.

I have attached the minimal reproducible code below

Minimal Reproducible Code

from __future__ import annotations
import discord
from discord.ext import bridge

bot = bridge.Bot(command_prefix="$", intents=discord.Intents.default())

@bot.bridge_command()
async def test(ctx, num: int):
    await ctx.send(f"__test__ {num=}")

Expected Results

The program runs and does nothing, as no call to bot.run was used

Actual Results

image

Stack trace using pretty_traceback:
image
Aliases for entries in sys.path:
: /Users/smartguy88-home/Library/Mobile Documents/comappleCloudDocs/Code Env/REPOS/DiscordBotTestbedH
: /Users/smartguy88-home/.pyenv/versions/3.10.3/lib/python3.10/site-packages
Traceback (most recent call last):
/bug.py 10: async def test(ctx, num: int):
/discord/ext/bridge/bot.py decorator 73: self.add_bridge_command(result)
/discord/ext/bridge/bot.py add_bridge_command 58: command.add_to(self) # type: ignore
/discord/ext/bridge/core.py add_to 178: bot.add_application_command(self.slash_variant)
/discord/bot.py add_application_command 136: command.cog = None
/discord/commands/core.py cog 777: self._validate_parameters()
/discord/commands/core.py _validate_parameters 670: self.options: List[Option] = self._parse_options(params)
/discord/commands/core.py _parse_options 709: option = Option(option)
/discord/commands/options.py init 199: self.input_type = SlashCommandOptionType.from_datatype(input_type)
/discord/enums.py from_datatype 689: if datatype.name in ["Member", "User"]:
AttributeError: 'str' object has no attribute 'name'

Intents

discord.Intents.default()

System Information

  • Python v3.10.3-final
  • py-cord v2.1.1-final
  • aiohttp v3.7.4.post0
  • system info: Darwin 21.5.0 Darwin Kernel Version 21.5.0: Tue Apr 26 20:57:23 PDT 2022; root:xnu-8020.121.3~2/RELEASE_ARM64_T8110

Checklist

  • I have searched the open issues for duplicates.
  • I have shown the entire traceback, if possible.
  • I have removed my token from display, if visible.

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions