Skip to content

Commit e61064d

Browse files
authored
types
1 parent c929c67 commit e61064d

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

discord/ui/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
from .item import Item, ItemCallbackType
4848
from .view import View
4949

50-
__all__ = "ComponentUI"
50+
__all__ = "ItemInterface"
5151

5252

5353
if TYPE_CHECKING:
@@ -59,7 +59,7 @@
5959
from ..types.components import Component as ComponentPayload
6060

6161

62-
class ComponentUI:
62+
class ItemInterface:
6363
"""The base structure for classes that contain :class:`~discord.ui.Item`.
6464
6565
.. versionadded:: 2.7

discord/ui/modal.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
from ..enums import ComponentType
1212
from ..utils import find
13-
from .core import ComponentUI
13+
from .core import ItemInterface
1414
from .input_text import InputText
1515
from .item import Item
1616
from .label import Label
@@ -36,7 +36,7 @@
3636
ModalItem = Union[Item[M]]
3737

3838

39-
class BaseModal(ComponentUI):
39+
class BaseModal(ItemInterface):
4040
"""Represents a UI modal.
4141
4242
This object must be inherited to create a UI within Discord.
@@ -130,9 +130,9 @@ def children(self) -> list[ModalItem]:
130130
@children.setter
131131
def children(self, value: list[ModalItem]):
132132
for item in value:
133-
if not isinstance(item, (InputText, Item)):
133+
if not isinstance(item, Item):
134134
raise TypeError(
135-
"all Modal children must be InputText or Item, not"
135+
"all BaseModal children must be Item, not"
136136
f" {item.__class__.__name__}"
137137
)
138138
self._children = value
@@ -268,16 +268,20 @@ class Modal(BaseModal):
268268

269269
def __init__(
270270
self,
271-
*children: ModalItem,
271+
*children: InputText,
272272
title: str,
273273
custom_id: str | None = None,
274274
timeout: float | None = None,
275275
) -> None:
276276
super().__init__(*children, title=title, custom_id=custom_id, timeout=timeout)
277277
self._weights = _ModalWeights(self._children)
278278

279+
@property
280+
def children(self) -> list[InputText]:
281+
return self._children
282+
279283
@children.setter
280-
def children(self, value: list[ModalItem]):
284+
def children(self, value: list[InputText]):
281285
for item in value:
282286
if not isinstance(item, InputText):
283287
raise TypeError(
@@ -323,12 +327,12 @@ def add_item(self, item: InputText) -> Self:
323327
super().add_item(item)
324328
return self
325329

326-
def remove_item(self, item: ModalItem) -> Self:
327-
"""Removes a component from the modal.
330+
def remove_item(self, item: InputText) -> Self:
331+
"""Removes an InputText from the modal.
328332
329333
Parameters
330334
----------
331-
item: Union[class:`InputText`, :class:`Item`]
335+
item: Union[class:`InputText`]
332336
The item to remove from the modal.
333337
"""
334338

@@ -371,6 +375,10 @@ def __init__(
371375
) -> None:
372376
super().__init__(*children, title=title, custom_id=custom_id, timeout=timeout)
373377

378+
@property
379+
def children(self) -> list[ModalItem]:
380+
return self._children
381+
374382
@children.setter
375383
def children(self, value: list[ModalItem]):
376384
for item in value:

discord/ui/view.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import time
3232
from functools import partial
3333
from itertools import groupby
34-
from typing import TYPE_CHECKING, Any, ClassVar, Iterator, Sequence, TypeVar
34+
from typing import TYPE_CHECKING, Any, ClassVar, Iterator, Sequence, TypeVar, Self
3535

3636
from ..components import ActionRow as ActionRowComponent
3737
from ..components import Button as ButtonComponent
@@ -47,7 +47,7 @@
4747
from ..components import Thumbnail as ThumbnailComponent
4848
from ..components import _component_factory
4949
from ..utils import find
50-
from .core import ComponentUI
50+
from .core import ItemInterface
5151
from .item import Item, ItemCallbackType
5252

5353
__all__ = (
@@ -198,7 +198,7 @@ def fits_legacy(self, item) -> bool:
198198
return self.weights[-1] + item.width <= 5
199199

200200

201-
class BaseView(ComponentUI):
201+
class BaseView(ItemInterface):
202202
"""The base class for UI views used in messages."""
203203

204204
MAX_ITEMS: int

0 commit comments

Comments
 (0)