Skip to content
Merged
Show file tree
Hide file tree
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
25 changes: 14 additions & 11 deletions disnake/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
if TYPE_CHECKING:
from typing import TypeAlias

from typing_extensions import Self
from typing_extensions import Self, TypeForm

from .emoji import Emoji
from .message import Attachment
Expand Down Expand Up @@ -291,8 +291,9 @@ def __init__(self, data: ActionRowPayload) -> None:
self.type: Literal[ComponentType.action_row] = ComponentType.action_row
self.id = data.get("id", 0)

children = [_component_factory(d) for d in data.get("components", [])]
self.children: list[ActionRowChildComponentT] = children # pyright: ignore[reportAttributeAccessIssue]
self.children: list[ActionRowChildComponentT] = [
_component_factory(d, type=ActionRowChildComponentT) for d in data.get("components", [])
]

def to_dict(self) -> ActionRowPayload:
return {
Expand Down Expand Up @@ -1065,8 +1066,9 @@ def __init__(self, data: SectionComponentPayload) -> None:
_component_factory(d, type=SectionChildComponent) for d in data.get("components", [])
]

accessory = _component_factory(data["accessory"])
self.accessory: SectionAccessoryComponent = accessory # pyright: ignore[reportAttributeAccessIssue]
self.accessory: SectionAccessoryComponent = _component_factory(
data["accessory"], type=SectionAccessoryComponent
)

def to_dict(self) -> SectionComponentPayload:
return {
Expand Down Expand Up @@ -1514,8 +1516,9 @@ def __init__(self, data: ContainerComponentPayload) -> None:
self.type: Literal[ComponentType.container] = ComponentType.container
self.id = data.get("id", 0)

components = [_component_factory(d) for d in data.get("components", [])]
self.children: list[ContainerChildComponent] = components # pyright: ignore[reportAttributeAccessIssue]
self.children: list[ContainerChildComponent] = [
_component_factory(d, type=ContainerChildComponent) for d in data.get("components", [])
]

self.accent_colour: Colour | None = (
Colour(accent_color) if (accent_color := data.get("accent_color")) is not None else None
Expand Down Expand Up @@ -1586,8 +1589,9 @@ def __init__(self, data: LabelComponentPayload) -> None:
self.text: str = data["label"]
self.description: str | None = data.get("description")

component = _component_factory(data["component"])
self.component: LabelChildComponent = component # pyright: ignore[reportAttributeAccessIssue]
self.component: LabelChildComponent = _component_factory(
data["component"], type=LabelChildComponent
)

def to_dict(self) -> LabelComponentPayload:
payload: LabelComponentPayload = {
Expand Down Expand Up @@ -1994,8 +1998,7 @@ def handle_media_item_input(value: MediaItemInput) -> UnfurledMediaItem:


# NOTE: The type param is purely for type-checking, it has no implications on runtime behavior.
# FIXME: could be improved with https://peps.python.org/pep-0747/
def _component_factory(data: ComponentPayload, *, type: type[C] = Component) -> C:
def _component_factory(data: ComponentPayload, *, type: TypeForm[C] = Component) -> C:
component_type = data["type"]

try:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ codemod = [
]
typing = [
# this is not pyright itself, but the python wrapper
"pyright==1.1.410",
"pyright==1.1.414",
# all type-check only dependencies are defined in noxfile.py.
]
test = [
Expand Down
Loading