Skip to content

Static component ParamSpecs #102

@Trimatix

Description

@Trimatix

Here's my current idea for the design:

class StaticComponents(StaticComponentIDsEnum):
    Private_Thing: StaticComponentID[int] = 1

@staticComponentCallback(StaticComponents.Private_Thing)
async def showHelpPageStatic(self, interaction: Interaction, userId: str): # type checker error: (Self, Interaction, str) -> Coroutine is not compatible with (Self, Interaction, int) -> Coroutine
    ...

userId = "abc"
privateThingButton = StaticComponents.PrivateThing(Button(), userId) # type checker error: no overload (Button, str) found, expected (ComponentBase, int)

The StaticComponentID hint should be generic in a ParamSpec. It can then Concatenate with self and interaction types to get the expected callback signature, and with the discord component base class to get the component constructor signature.
Remember that some callbacks don't accept any parameters.

If it's easier, we could use a descriptor instead of a type hint. That way the static component ID would also be aware of its name.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions