Skip to content

Commit 4ee4b70

Browse files
authored
guys don't you love typing changes
1 parent 45a5c44 commit 4ee4b70

File tree

14 files changed

+165
-152
lines changed

14 files changed

+165
-152
lines changed

discord/client.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@
7474
from .message import Message
7575
from .poll import Poll
7676
from .soundboard import SoundboardSound
77-
from .ui.item import Item
77+
from .ui.item import Item, ViewItem
78+
from .ui.modal import BaseModal
7879
from .voice_client import VoiceProtocol
7980

8081
__all__ = ("Client",)
@@ -546,7 +547,7 @@ async def on_error(self, event_method: str, *args: Any, **kwargs: Any) -> None:
546547
traceback.print_exc()
547548

548549
async def on_view_error(
549-
self, error: Exception, item: Item, interaction: Interaction
550+
self, error: Exception, item: ViewItem, interaction: Interaction
550551
) -> None:
551552
"""|coro|
552553
@@ -558,7 +559,7 @@ async def on_view_error(
558559
----------
559560
error: :class:`Exception`
560561
The exception that was raised.
561-
item: :class:`Item`
562+
item: :class:`ViewItem`
562563
The item that the user interacted with.
563564
interaction: :class:`Interaction`
564565
The interaction that was received.
@@ -572,7 +573,7 @@ async def on_view_error(
572573
error.__class__, error, error.__traceback__, file=sys.stderr
573574
)
574575

575-
async def on_modal_error(self, error: Exception, interaction: Interaction) -> None:
576+
async def on_modal_error(self, error: Exception, modal: BaseModal, interaction: Interaction) -> None:
576577
"""|coro|
577578
578579
The default modal error handler provided by the client.
@@ -584,11 +585,13 @@ async def on_modal_error(self, error: Exception, interaction: Interaction) -> No
584585
----------
585586
error: :class:`Exception`
586587
The exception that was raised.
588+
modal: :class:`BaseModal`
589+
The modal that failed the dispatch.
587590
interaction: :class:`Interaction`
588591
The interaction that was received.
589592
"""
590593

591-
print(f"Ignoring exception in modal {interaction.modal}:", file=sys.stderr)
594+
print(f"Ignoring exception in modal {modal}:", file=sys.stderr)
592595
traceback.print_exception(
593596
error.__class__, error, error.__traceback__, file=sys.stderr
594597
)

discord/ui/button.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from ..components import Button as ButtonComponent
3333
from ..enums import ButtonStyle, ComponentType
3434
from ..partial_emoji import PartialEmoji, _EmojiTag
35-
from .item import Item, ItemCallbackType
35+
from .item import ViewItem, ItemCallbackType
3636

3737
__all__ = (
3838
"Button",
@@ -47,7 +47,7 @@
4747
V = TypeVar("V", bound="BaseView", covariant=True)
4848

4949

50-
class Button(Item[V]):
50+
class Button(ViewItem[V]):
5151
"""Represents a UI button.
5252
5353
.. versionadded:: 2.0

discord/ui/container.py

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from .action_row import ActionRow
1212
from .button import Button
1313
from .file import File
14-
from .item import Item, ItemCallbackType
14+
from .item import ViewItem, ItemCallbackType
1515
from .media_gallery import MediaGallery
1616
from .section import Section
1717
from .select import Select
@@ -32,7 +32,7 @@
3232
V = TypeVar("V", bound="DesignerView", covariant=True)
3333

3434

35-
class Container(Item[V]):
35+
class Container(ViewItem[V]):
3636
"""Represents a UI Container.
3737
3838
The current items supported are as follows:
@@ -48,7 +48,7 @@ class Container(Item[V]):
4848
4949
Parameters
5050
----------
51-
*items: :class:`Item`
51+
*items: :class:`ViewItem`
5252
The initial items in this container.
5353
colour: Union[:class:`Colour`, :class:`int`]
5454
The accent colour of the container. Aliased to ``color`` as well.
@@ -75,15 +75,15 @@ def __init_subclass__(cls) -> None:
7575

7676
def __init__(
7777
self,
78-
*items: Item,
78+
*items: ViewItem,
7979
colour: int | Colour | None = None,
8080
color: int | Colour | None = None,
8181
spoiler: bool = False,
8282
id: int | None = None,
8383
):
8484
super().__init__()
8585

86-
self.items: list[Item] = []
86+
self.items: list[ViewItem] = []
8787

8888
self._underlying = ContainerComponent._raw_construct(
8989
type=ComponentType.container,
@@ -96,30 +96,30 @@ def __init__(
9696
for i in items:
9797
self.add_item(i)
9898

99-
def _add_component_from_item(self, item: Item):
99+
def _add_component_from_item(self, item: ViewItem):
100100
self._underlying.components.append(item._underlying)
101101

102-
def _set_components(self, items: list[Item]):
102+
def _set_components(self, items: list[ViewItem]):
103103
self._underlying.components.clear()
104104
for item in items:
105105
self._add_component_from_item(item)
106106

107-
def add_item(self, item: Item) -> Self:
107+
def add_item(self, item: ViewItem) -> Self:
108108
"""Adds an item to the container.
109109
110110
Parameters
111111
----------
112-
item: :class:`Item`
112+
item: :class:`ViewItem`
113113
The item to add to the container.
114114
115115
Raises
116116
------
117117
TypeError
118-
An :class:`Item` was not passed.
118+
A :class:`ViewItem` was not passed.
119119
"""
120120

121-
if not isinstance(item, Item):
122-
raise TypeError(f"expected Item not {item.__class__!r}")
121+
if not isinstance(item, ViewItem):
122+
raise TypeError(f"expected ViewItem not {item.__class__!r}")
123123

124124
if isinstance(item, (Button, Select)):
125125
raise TypeError(
@@ -135,12 +135,12 @@ def add_item(self, item: Item) -> Self:
135135
self._add_component_from_item(item)
136136
return self
137137

138-
def remove_item(self, item: Item | str | int) -> Self:
138+
def remove_item(self, item: ViewItem | str | int) -> Self:
139139
"""Removes an item from the container. If an int or str is passed, it will remove by Item :attr:`id` or ``custom_id`` respectively.
140140
141141
Parameters
142142
----------
143-
item: Union[:class:`Item`, :class:`int`, :class:`str`]
143+
item: Union[:class:`ViewItem`, :class:`int`, :class:`str`]
144144
The item, ``id``, or item ``custom_id`` to remove from the container.
145145
"""
146146

@@ -155,7 +155,7 @@ def remove_item(self, item: Item | str | int) -> Self:
155155
pass
156156
return self
157157

158-
def get_item(self, id: str | int) -> Item | None:
158+
def get_item(self, id: str | int) -> ViewItem | None:
159159
"""Get an item from this container. Roughly equivalent to `utils.get(container.items, ...)`.
160160
If an ``int`` is provided, the item will be retrieved by ``id``, otherwise by ``custom_id``.
161161
This method will also search for nested items.
@@ -167,7 +167,7 @@ def get_item(self, id: str | int) -> Item | None:
167167
168168
Returns
169169
-------
170-
Optional[:class:`Item`]
170+
Optional[:class:`ViewItem`]
171171
The item with the matching ``id`` or ``custom_id`` if it exists.
172172
"""
173173
if not id:
@@ -183,7 +183,7 @@ def get_item(self, id: str | int) -> Item | None:
183183

184184
def add_row(
185185
self,
186-
*items: Item,
186+
*items: ViewItem,
187187
id: int | None = None,
188188
) -> Self:
189189
"""Adds an :class:`ActionRow` to the container.
@@ -204,8 +204,8 @@ def add_row(
204204

205205
def add_section(
206206
self,
207-
*items: Item,
208-
accessory: Item,
207+
*items: ViewItem,
208+
accessory: ViewItem,
209209
id: int | None = None,
210210
) -> Self:
211211
"""Adds a :class:`Section` to the container.
@@ -215,10 +215,10 @@ def add_section(
215215
216216
Parameters
217217
----------
218-
*items: :class:`Item`
218+
*items: :class:`ViewItem`
219219
The items contained in this section, up to 3.
220220
Currently only supports :class:`~discord.ui.TextDisplay`.
221-
accessory: Optional[:class:`Item`]
221+
accessory: Optional[:class:`ViewItem`]
222222
The section's accessory. This is displayed in the top right of the section.
223223
Currently only supports :class:`~discord.ui.Button` and :class:`~discord.ui.Thumbnail`.
224224
id: Optional[:class:`int`]
@@ -246,7 +246,7 @@ def add_text(self, content: str, id: int | None = None) -> Self:
246246

247247
def add_gallery(
248248
self,
249-
*items: Item,
249+
*items: ViewItem,
250250
id: int | None = None,
251251
) -> Self:
252252
"""Adds a :class:`MediaGallery` to the container.
@@ -338,7 +338,7 @@ def colour(self, value: int | Colour | None): # type: ignore
338338

339339
color = colour
340340

341-
@Item.view.setter
341+
@ViewItem.view.setter
342342
def view(self, value):
343343
self._view = value
344344
for item in self.items:
@@ -365,13 +365,13 @@ def refresh_component(self, component: ContainerComponent) -> None:
365365
x.refresh_component(y)
366366
i += 1
367367

368-
def disable_all_items(self, *, exclusions: list[Item] | None = None) -> Self:
368+
def disable_all_items(self, *, exclusions: list[ViewItem] | None = None) -> Self:
369369
"""
370370
Disables all buttons and select menus in the container.
371371
372372
Parameters
373373
----------
374-
exclusions: Optional[List[:class:`Item`]]
374+
exclusions: Optional[List[:class:`ViewItem`]]
375375
A list of items in `self.items` to not disable from the view.
376376
"""
377377
for item in self.walk_items():
@@ -381,13 +381,13 @@ def disable_all_items(self, *, exclusions: list[Item] | None = None) -> Self:
381381
item.disabled = True
382382
return self
383383

384-
def enable_all_items(self, *, exclusions: list[Item] | None = None) -> Self:
384+
def enable_all_items(self, *, exclusions: list[ViewItem] | None = None) -> Self:
385385
"""
386386
Enables all buttons and select menus in the container.
387387
388388
Parameters
389389
----------
390-
exclusions: Optional[List[:class:`Item`]]
390+
exclusions: Optional[List[:class:`ViewItem`]]
391391
A list of items in `self.items` to not enable from the view.
392392
"""
393393
for item in self.walk_items():
@@ -397,7 +397,7 @@ def enable_all_items(self, *, exclusions: list[Item] | None = None) -> Self:
397397
item.disabled = False
398398
return self
399399

400-
def walk_items(self) -> Iterator[Item]:
400+
def walk_items(self) -> Iterator[ViewItem]:
401401
for item in self.items:
402402
if hasattr(item, "walk_items"):
403403
yield from item.walk_items()

discord/ui/file.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from ..components import FileComponent, UnfurledMediaItem, _component_factory
77
from ..enums import ComponentType
8-
from .item import Item
8+
from .item import ViewItem
99

1010
__all__ = ("File",)
1111

@@ -18,7 +18,7 @@
1818
V = TypeVar("V", bound="DesignerView", covariant=True)
1919

2020

21-
class File(Item[V]):
21+
class File(ViewItem[V]):
2222
"""Represents a UI File.
2323
2424
.. note::

discord/ui/item.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def __init__(self):
163163
self._view: V | None = None
164164
self._row: int | None = None
165165
self._rendered_row: int | None = None
166-
self.parent: Item | BaseView | None = self.view
166+
self.parent: ViewItem | BaseView | None = self.view
167167

168168
@property
169169
def row(self) -> int | None:
@@ -254,14 +254,14 @@ class ModalItem(Item[M]):
254254

255255
def __init__(self):
256256
super().__init__()
257-
self._modal: V | None = None
258-
self.parent: Item | BaseModal | None = self.modal
257+
self._modal: M | None = None
258+
self.parent: ModalItem | BaseModal | None = self.modal
259259

260260
def refresh_from_modal(self, interaction: Interaction, data: dict) -> None:
261261
return None
262262

263263
@property
264-
def modal(self) -> V | None:
264+
def modal(self) -> M | None:
265265
"""Gets the parent modal associated with this item. This is typically set
266266
automatically when the item is added to a modal.
267267

discord/ui/media_gallery.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from ..components import MediaGallery as MediaGalleryComponent
66
from ..components import MediaGalleryItem
77
from ..enums import ComponentType
8-
from .item import Item
8+
from .item import ViewItem
99

1010
__all__ = ("MediaGallery",)
1111

@@ -20,7 +20,7 @@
2020
V = TypeVar("V", bound="DesignerView", covariant=True)
2121

2222

23-
class MediaGallery(Item[V]):
23+
class MediaGallery(ViewItem[V]):
2424
"""Represents a UI Media Gallery. Galleries may contain up to 10 :class:`MediaGalleryItem` objects.
2525
2626
.. versionadded:: 2.7
@@ -105,10 +105,6 @@ def add_item(
105105

106106
return self.append_item(item)
107107

108-
@Item.view.setter
109-
def view(self, value):
110-
self._view = value
111-
112108
@property
113109
def type(self) -> ComponentType:
114110
return self._underlying.type

0 commit comments

Comments
 (0)