Skip to content

Commit 4e8962d

Browse files
committed
fix: don't pass kwargs to modal callbacks that only have ctx
Fixes interactions-py#1517. Supercedes interactions-py#1584.
1 parent ebe2e1a commit 4e8962d

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

interactions/client/client.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,6 +1344,17 @@ def add_modal_callback(self, command: ModalCommand) -> None:
13441344
Args:
13451345
command: The command to add
13461346
"""
1347+
# test for parameters that arent the ctx (or self)
1348+
if command.has_binding:
1349+
callback = functools.partial(command.callback, None, None)
1350+
else:
1351+
callback = functools.partial(command.callback, None)
1352+
1353+
if not inspect.signature(callback).parameters:
1354+
# if there are none, notify the command to just pass the ctx and not kwargs
1355+
# TODO: just make modal callbacks not pass kwargs at all (breaking)
1356+
command._just_ctx = True
1357+
13471358
for listener in command.listeners:
13481359
if isinstance(listener, re.Pattern):
13491360
if listener in self._regex_component_callbacks.keys():

interactions/models/internal/application_commands.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,12 @@ class ComponentCommand(InteractionCommand):
844844

845845
@attrs.define(eq=False, order=False, hash=False, kw_only=True)
846846
class ModalCommand(ComponentCommand):
847-
...
847+
_just_ctx: bool = attrs.field(repr=False, default=False)
848+
849+
async def call_callback(self, callback: Callable, context: "BaseContext") -> None:
850+
if self._just_ctx:
851+
return await self.call_with_binding(callback, context)
852+
return await super().call_callback(callback, context)
848853

849854

850855
def _unpack_helper(iterable: typing.Iterable[str]) -> list[str]:

0 commit comments

Comments
 (0)