Skip to content

fix: typehint channels correctly in event classes #1538

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

Merged
merged 1 commit into from
Aug 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 23 additions & 19 deletions interactions/api/events/discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ async def an_event_handler(event: ChannelCreate):

"""

from typing import TYPE_CHECKING, List, Sequence, Union, Optional
from typing import TYPE_CHECKING, List, Optional, Sequence, Union

import attrs

import interactions.models
from interactions.api.events.base import GuildEvent, BaseEvent
from interactions.api.events.base import BaseEvent, GuildEvent
from interactions.client.const import Absent
from interactions.client.utils.attr_utils import docs
from interactions.models.discord.snowflake import to_snowflake
Expand Down Expand Up @@ -99,30 +99,34 @@ async def an_event_handler(event: ChannelCreate):


if TYPE_CHECKING:
from interactions.models.discord.guild import Guild, GuildIntegration
from interactions.models.discord.channel import BaseChannel, TYPE_THREAD_CHANNEL, VoiceChannel
from interactions.models.discord.message import Message
from interactions.models.discord.timestamp import Timestamp
from interactions.models.discord.user import Member, User, BaseUser
from interactions.models.discord.snowflake import Snowflake_Type
from interactions.models.discord.activity import Activity
from interactions.models.discord.app_perms import ApplicationCommandPermission
from interactions.models.discord.auto_mod import AutoModerationAction, AutoModRule
from interactions.models.discord.channel import (
TYPE_ALL_CHANNEL,
TYPE_THREAD_CHANNEL,
VoiceChannel,
)
from interactions.models.discord.emoji import CustomEmoji, PartialEmoji
from interactions.models.discord.guild import Guild, GuildIntegration
from interactions.models.discord.message import Message
from interactions.models.discord.reaction import Reaction
from interactions.models.discord.role import Role
from interactions.models.discord.scheduled_event import ScheduledEvent
from interactions.models.discord.snowflake import Snowflake_Type
from interactions.models.discord.stage_instance import StageInstance
from interactions.models.discord.sticker import Sticker
from interactions.models.discord.timestamp import Timestamp
from interactions.models.discord.user import BaseUser, Member, User
from interactions.models.discord.voice_state import VoiceState
from interactions.models.discord.stage_instance import StageInstance
from interactions.models.discord.auto_mod import AutoModerationAction, AutoModRule
from interactions.models.discord.reaction import Reaction
from interactions.models.discord.app_perms import ApplicationCommandPermission
from interactions.models.discord.scheduled_event import ScheduledEvent


@attrs.define(eq=False, order=False, hash=False, kw_only=False)
class AutoModExec(BaseEvent):
"""Dispatched when an auto modation action is executed"""

execution: "AutoModerationAction" = attrs.field(repr=False, metadata=docs("The executed auto mod action"))
channel: "BaseChannel" = attrs.field(repr=False, metadata=docs("The channel the action was executed in"))
channel: "TYPE_ALL_CHANNEL" = attrs.field(repr=False, metadata=docs("The channel the action was executed in"))
guild: "Guild" = attrs.field(repr=False, metadata=docs("The guild the action was executed in"))


Expand Down Expand Up @@ -164,18 +168,18 @@ class ApplicationCommandPermissionsUpdate(BaseEvent):
class ChannelCreate(BaseEvent):
"""Dispatched when a channel is created."""

channel: "BaseChannel" = attrs.field(repr=False, metadata=docs("The channel this event is dispatched from"))
channel: "TYPE_ALL_CHANNEL" = attrs.field(repr=False, metadata=docs("The channel this event is dispatched from"))


@attrs.define(eq=False, order=False, hash=False, kw_only=False)
class ChannelUpdate(BaseEvent):
"""Dispatched when a channel is updated."""

before: "BaseChannel" = attrs.field(
before: "TYPE_ALL_CHANNEL" = attrs.field(
repr=False,
)
"""Channel before this event. MISSING if it was not cached before"""
after: "BaseChannel" = attrs.field(
after: "TYPE_ALL_CHANNEL" = attrs.field(
repr=False,
)
"""Channel after this event"""
Expand Down Expand Up @@ -226,7 +230,7 @@ class ThreadListSync(BaseEvent):
repr=False,
)
"""The parent channel ids whose threads are being synced. If omitted, then threads were synced for the entire guild. This array may contain channel_ids that have no active threads as well, so you know to clear that data."""
threads: List["BaseChannel"] = attrs.field(
threads: List["TYPE_ALL_CHANNEL"] = attrs.field(
repr=False,
)
"""all active threads in the given channels that the current user can access"""
Expand Down Expand Up @@ -618,7 +622,7 @@ class TypingStart(BaseEvent):
repr=False,
)
"""The user who started typing"""
channel: "BaseChannel" = attrs.field(
channel: "TYPE_ALL_CHANNEL" = attrs.field(
repr=False,
)
"""The channel typing is in"""
Expand Down