Repository: Rapptz/discord.py
File: discord/interactions.py (Python)

Code before:
    id: :class:`str`
        The activity instance ID.
    """

    __slots__ = ('id',)

    def __init__(self, data: InteractionCallbackActivityPayload) -> None:
        self.id: str = data['id']


class InteractionCallback(Generic[ClientT]):
    """Represents an interaction response callback.

    .. versionadded:: 2.5

    Attributes
    ----------
    id: :class:`int`
        The interaction ID.
    type: :class:`InteractionResponseType`
        The interaction callback response type.
    resource: Optional[Union[:class:`InteractionMessage`, :class:`InteractionCallbackActivityInstance`]]
        The resource that the interaction response created. If a message was sent, this will be
        a :class:`InteractionMessage`, else if an activity was launched this will be a
        :class:`InteractionCallbackActivityInstance`. In any other case, this will be ``None``.
    message_id: Optional[:class:`int`]
        The message ID of the resource. Only available if the resource is a :class:`InteractionMessage`.
    activity_id: Optional[:class:`str`]
        The activity ID of the resource. Only available if the resource is a :class:`InteractionCallbackActivityInstance`.
    """

    def __init__(
        self,
        *,
        data: InteractionCallbackPayload,
        parent: Interaction[ClientT],
        state: ConnectionState,
        type: InteractionResponseType,
    ) -> None:
        self._state: ConnectionState = state
        self._parent: Interaction[ClientT] = parent
        self.type: InteractionResponseType = type
        self._update(data)

    def _update(self, data: InteractionCallbackPayload) -> None:
        interaction = data['interaction']

        self.id: int = int(interaction['id'])
        self._thinking: bool = interaction.get('response_message_loading', False)
        self._ephemeral: bool = interaction.get('response_message_ephemeral', False)


Review comment (refactor):
For now, this is fine. In the future it might make sense to refactor this into a type alias that is referenced later but that might require Sphinx changes. I'm bringing this up just to make note of it, no change required here.

Code after:
    .. versionadded:: 2.5

    Attributes
    ----------
    id: :class:`str`
        The activity instance ID.
    """

    __slots__ = ('id',)

    def __init__(self, data: InteractionCallbackActivityPayload) -> None:
        self.id: str = data['id']


class InteractionCallback(Generic[ClientT]):
    """Represents an interaction response callback.

    .. versionadded:: 2.5

    Attributes
    ----------
    id: :class:`int`
        The interaction ID.
    type: :class:`InteractionResponseType`
        The interaction callback response type.
    resource: Optional[Union[:class:`InteractionMessage`, :class:`InteractionCallbackActivityInstance`]]
        The resource that the interaction response created. If a message was sent, this will be
        a :class:`InteractionMessage`. If an activity was launched this will be a
        :class:`InteractionCallbackActivityInstance`. In any other case, this will be ``None``.
    message_id: Optional[:class:`int`]
        The message ID of the resource. Only available if the resource is a :class:`InteractionMessage`.
    activity_id: Optional[:class:`str`]
        The activity ID of the resource. Only available if the resource is a :class:`InteractionCallbackActivityInstance`.
    """

    __slots__ = (
        '_state',
        '_parent',
        'type',
        'id',
        '_thinking',
        '_ephemeral',
        'message_id',
        'activity_id',
        'resource',
    )

    def __init__(
        self,
        *,
        data: InteractionCallbackPayload,