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

bridge.Context not a valid context typehint #2378

Open
3 tasks done
Revnoplex opened this issue Mar 2, 2024 · 0 comments
Open
3 tasks done

bridge.Context not a valid context typehint #2378

Revnoplex opened this issue Mar 2, 2024 · 0 comments
Labels
on hold unconfirmed bug A bug report that needs triaging

Comments

@Revnoplex
Copy link
Contributor

Revnoplex commented Mar 2, 2024

Summary

Using bridge.Context in a bridge command raises a TypeError acting like other invalid typehints even though specified as a feature in #2106

Reproduction Steps

Use a bridge command with the context type hint ctx: bridge.Context

Minimal Reproducible Code

@bridge.bridge_command(name='test', description="Hello World")
@commands.cooldown(**config.default_cooldown_options)
@commands.bot_has_permissions(send_messages=True)
async def test_cmd(self, ctx: bridge.Context):  
    await ctx.respond("Hello World")

Expected Results

bridge.Context to pass pycord's type hinting checks

Actual Results

bridge.Context fails pycord's type hinting checks which raises TypeError: Invalid usage of typing.Union
Traceback associated:

  File "bot-dir/venv/lib/python3.11/site-packages/discord/cog.py", line 778, in _load_from_module_spec
    spec.loader.exec_module(lib)  # type: ignore
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "<frozen importlib._bootstrap_external>", line 940, in exec_module

  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed

  File "bot-dir/cogs/testing.py", line 13, in <module>
    class Testing(config.RevnobotCog):

  File "bot-dir/cogs/testing.py", line 21, in Testing
    @bridge.bridge_command(name='test', description="Hello World")
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "bot-dir/venv/lib/python3.11/site-packages/discord/ext/bridge/core.py", line 425, in decorator
    return BridgeCommand(callback, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "bot-dir/venv/lib/python3.11/site-packages/discord/ext/bridge/core.py", line 168, in __init__
    ) or BridgeSlashCommand(callback, **kwargs)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "bot-dir/venv/lib/python3.11/site-packages/discord/ext/bridge/core.py", line 83, in __init__
    super().__init__(func, **kwargs)

  File "bot-dir/venv/lib/python3.11/site-packages/discord/commands/core.py", line 694, in __init__
    self._validate_parameters()

  File "bot-dir/venv/lib/python3.11/site-packages/discord/commands/core.py", line 712, in _validate_parameters
    self.options = self._parse_options(params)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "bot-dir/venv/lib/python3.11/site-packages/discord/commands/core.py", line 760, in _parse_options
    option = Option(option.__args__)
             ^^^^^^^^^^^^^^^^^^^^^^^

  File "bot-dir/venv/lib/python3.11/site-packages/discord/commands/options.py", line 232, in __init__
    raise exc

  File "bot-dir/venv/lib/python3.11/site-packages/discord/commands/options.py", line 227, in __init__
    self.input_type = SlashCommandOptionType.from_datatype(input_type)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "bot-dir/venv/lib/python3.11/site-packages/discord/enums.py", line 798, in from_datatype
    raise TypeError("Invalid usage of typing.Union")

Intents

all

System Information

  • Python v3.11.7-final
  • py-cord v2.5.None-final
  • aiohttp v3.9.3
  • system info: Linux 6.7.6-arch1-1 Update README.rst #1 SMP PREEMPT_DYNAMIC Fri, 23 Feb 2024 16:31:48 +0000

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

Also neither does Union[bridge.BridgeExtContext, bridge.BridgeApplicationContext] passes pycord's context type hint checks

@Revnoplex Revnoplex added the unconfirmed bug A bug report that needs triaging label Mar 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
on hold unconfirmed bug A bug report that needs triaging
Projects
None yet
Development

No branches or pull requests

2 participants