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
Additional Context
Also neither does Union[bridge.BridgeExtContext, bridge.BridgeApplicationContext] passes pycord's context type hint checks
Summary
Using
bridge.Contextin a bridge command raises aTypeErroracting like other invalid typehints even though specified as a feature in #2106Reproduction Steps
Use a bridge command with the context type hint
ctx: bridge.ContextMinimal Reproducible Code
Expected Results
bridge.Contextto pass pycord's type hinting checksActual Results
bridge.Contextfails pycord's type hinting checks which raisesTypeError: Invalid usage of typing.UnionTraceback associated:
Intents
all
System Information
Checklist
Additional Context
Also neither does
Union[bridge.BridgeExtContext, bridge.BridgeApplicationContext]passes pycord's context type hint checks