Skip to content

Commit 9ca373a

Browse files
authored
docs and typing cleanup
1 parent b2ed0d1 commit 9ca373a

21 files changed

+114
-86
lines changed

discord/abc.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
from .types.channel import GuildChannel as GuildChannelPayload
9696
from .types.channel import OverwriteType
9797
from .types.channel import PermissionOverwrite as PermissionOverwritePayload
98-
from .ui.view import View
98+
from .ui.view import BaseView
9999
from .user import ClientUser
100100

101101
PartialMessageableChannel = Union[
@@ -1355,7 +1355,7 @@ async def send(
13551355
allowed_mentions: AllowedMentions = ...,
13561356
reference: Message | MessageReference | PartialMessage = ...,
13571357
mention_author: bool = ...,
1358-
view: View = ...,
1358+
view: BaseView = ...,
13591359
poll: Poll = ...,
13601360
suppress: bool = ...,
13611361
silent: bool = ...,
@@ -1376,7 +1376,7 @@ async def send(
13761376
allowed_mentions: AllowedMentions = ...,
13771377
reference: Message | MessageReference | PartialMessage = ...,
13781378
mention_author: bool = ...,
1379-
view: View = ...,
1379+
view: BaseView = ...,
13801380
poll: Poll = ...,
13811381
suppress: bool = ...,
13821382
silent: bool = ...,
@@ -1397,7 +1397,7 @@ async def send(
13971397
allowed_mentions: AllowedMentions = ...,
13981398
reference: Message | MessageReference | PartialMessage = ...,
13991399
mention_author: bool = ...,
1400-
view: View = ...,
1400+
view: BaseView = ...,
14011401
poll: Poll = ...,
14021402
suppress: bool = ...,
14031403
silent: bool = ...,
@@ -1418,7 +1418,7 @@ async def send(
14181418
allowed_mentions: AllowedMentions = ...,
14191419
reference: Message | MessageReference | PartialMessage = ...,
14201420
mention_author: bool = ...,
1421-
view: View = ...,
1421+
view: BaseView = ...,
14221422
poll: Poll = ...,
14231423
suppress: bool = ...,
14241424
silent: bool = ...,
@@ -1509,7 +1509,7 @@ async def send(
15091509
If set, overrides the :attr:`~discord.AllowedMentions.replied_user` attribute of ``allowed_mentions``.
15101510
15111511
.. versionadded:: 1.6
1512-
view: :class:`discord.ui.View`
1512+
view: :class:`discord.ui.BaseView`
15131513
A Discord UI View to add to the message.
15141514
embeds: List[:class:`~discord.Embed`]
15151515
A list of embeds to upload. Must be a maximum of 10.

discord/channel.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
from .types.channel import VoiceChannelEffectSendEvent as VoiceChannelEffectSend
108108
from .types.snowflake import SnowflakeList
109109
from .types.threads import ThreadArchiveDuration
110-
from .ui.view import View
110+
from .ui.view import BaseView
111111
from .user import BaseUser, ClientUser, User
112112
from .webhook import Webhook
113113

@@ -1217,7 +1217,7 @@ async def create_thread(
12171217
delete_message_after: float | None = None,
12181218
nonce: int | str | None = None,
12191219
allowed_mentions: AllowedMentions | None = None,
1220-
view: View | None = None,
1220+
view: BaseView | None = None,
12211221
applied_tags: list[ForumTag] | None = None,
12221222
suppress: bool = False,
12231223
silent: bool = False,
@@ -1262,7 +1262,7 @@ async def create_thread(
12621262
to the object, otherwise it uses the attributes set in :attr:`~discord.Client.allowed_mentions`.
12631263
If no object is passed at all then the defaults given by :attr:`~discord.Client.allowed_mentions`
12641264
are used instead.
1265-
view: :class:`discord.ui.View`
1265+
view: :class:`discord.ui.BaseView`
12661266
A Discord UI View to add to the message.
12671267
applied_tags: List[:class:`discord.ForumTag`]
12681268
A list of tags to apply to the new thread.

discord/client.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
from .sticker import GuildSticker, StandardSticker, StickerPack, _sticker_factory
6060
from .template import Template
6161
from .threads import Thread
62-
from .ui.view import View
62+
from .ui.view import BaseView
6363
from .user import ClientUser, User
6464
from .utils import MISSING
6565
from .voice_client import VoiceClient
@@ -552,7 +552,7 @@ async def on_view_error(
552552
553553
The default view error handler provided by the client.
554554
555-
This only fires for a view if you did not define its :func:`~discord.ui.View.on_error`.
555+
This only fires for a view if you did not define its :func:`~discord.ui.BaseView.on_error`.
556556
557557
Parameters
558558
----------
@@ -2037,8 +2037,8 @@ async def create_dm(self, user: Snowflake) -> DMChannel:
20372037
data = await state.http.start_private_message(user.id)
20382038
return state.add_dm_channel(data)
20392039

2040-
def add_view(self, view: View, *, message_id: int | None = None) -> None:
2041-
"""Registers a :class:`~discord.ui.View` for persistent listening.
2040+
def add_view(self, view: BaseView, *, message_id: int | None = None) -> None:
2041+
"""Registers a :class:`~discord.ui.BaseView` for persistent listening.
20422042
20432043
This method should be used for when a view is comprised of components
20442044
that last longer than the lifecycle of the program.
@@ -2047,7 +2047,7 @@ def add_view(self, view: View, *, message_id: int | None = None) -> None:
20472047
20482048
Parameters
20492049
----------
2050-
view: :class:`discord.ui.View`
2050+
view: :class:`discord.ui.BaseView`
20512051
The view to register for dispatching.
20522052
message_id: Optional[:class:`int`]
20532053
The message ID that the view is attached to. This is currently used to
@@ -2063,8 +2063,8 @@ def add_view(self, view: View, *, message_id: int | None = None) -> None:
20632063
and all their components have an explicitly provided ``custom_id``.
20642064
"""
20652065

2066-
if not isinstance(view, View):
2067-
raise TypeError(f"expected an instance of View not {view.__class__!r}")
2066+
if not isinstance(view, BaseView):
2067+
raise TypeError(f"expected an instance of BaseView not {view.__class__!r}")
20682068

20692069
if not view.is_persistent():
20702070
raise ValueError(
@@ -2075,7 +2075,7 @@ def add_view(self, view: View, *, message_id: int | None = None) -> None:
20752075
self._connection.store_view(view, message_id)
20762076

20772077
@property
2078-
def persistent_views(self) -> Sequence[View]:
2078+
def persistent_views(self) -> Sequence[BaseView]:
20792079
"""A sequence of persistent views added to the client.
20802080
20812081
.. versionadded:: 2.0

discord/interactions.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
from .types.interactions import InteractionMetadata as InteractionMetadataPayload
9090
from .types.interactions import MessageInteraction as MessageInteractionPayload
9191
from .ui.modal import Modal
92-
from .ui.view import View
92+
from .ui.view import BaseView
9393

9494
InteractionChannel = Union[
9595
VoiceChannel,
@@ -164,7 +164,7 @@ class Interaction:
164164
The command that this interaction belongs to.
165165
166166
.. versionadded:: 2.7
167-
view: Optional[:class:`View`]
167+
view: Optional[:class:`BaseView`]
168168
The view that this interaction belongs to.
169169
170170
.. versionadded:: 2.7
@@ -257,7 +257,7 @@ def _from_data(self, data: InteractionPayload):
257257
)
258258

259259
self.command: ApplicationCommand | None = None
260-
self.view: View | None = None
260+
self.view: BaseView | None = None
261261
self.modal: Modal | None = None
262262
self.attachment_size_limit: int = data.get("attachment_size_limit")
263263

@@ -522,7 +522,7 @@ async def edit_original_response(
522522
file: File = MISSING,
523523
files: list[File] = MISSING,
524524
attachments: list[Attachment] = MISSING,
525-
view: View | None = MISSING,
525+
view: BaseView | None = MISSING,
526526
allowed_mentions: AllowedMentions | None = None,
527527
delete_after: float | None = None,
528528
suppress: bool = False,
@@ -557,7 +557,7 @@ async def edit_original_response(
557557
allowed_mentions: :class:`AllowedMentions`
558558
Controls the mentions being processed in this message.
559559
See :meth:`.abc.Messageable.send` for more information.
560-
view: Optional[:class:`~discord.ui.View`]
560+
view: Optional[:class:`~discord.ui.BaseView`]
561561
The updated view to update this message with. If ``None`` is passed then
562562
the view is removed.
563563
delete_after: Optional[:class:`float`]
@@ -947,7 +947,7 @@ async def send_message(
947947
*,
948948
embed: Embed = None,
949949
embeds: list[Embed] = None,
950-
view: View = None,
950+
view: BaseView = None,
951951
tts: bool = False,
952952
ephemeral: bool = False,
953953
allowed_mentions: AllowedMentions = None,
@@ -972,7 +972,7 @@ async def send_message(
972972
``embeds`` parameter.
973973
tts: :class:`bool`
974974
Indicates if the message should be sent using text-to-speech.
975-
view: :class:`discord.ui.View`
975+
view: :class:`discord.ui.BaseView`
976976
The view to send with the message.
977977
ephemeral: :class:`bool`
978978
Indicates if the message should only be visible to the user who started the interaction.
@@ -1128,7 +1128,7 @@ async def edit_message(
11281128
file: File = MISSING,
11291129
files: list[File] = MISSING,
11301130
attachments: list[Attachment] = MISSING,
1131-
view: View | None = MISSING,
1131+
view: BaseView | None = MISSING,
11321132
delete_after: float | None = None,
11331133
suppress: bool | None = MISSING,
11341134
allowed_mentions: AllowedMentions | None = None,
@@ -1155,7 +1155,7 @@ async def edit_message(
11551155
attachments: List[:class:`Attachment`]
11561156
A list of attachments to keep in the message. If ``[]`` is passed
11571157
then all attachments are removed.
1158-
view: Optional[:class:`~discord.ui.View`]
1158+
view: Optional[:class:`~discord.ui.BaseView`]
11591159
The updated view to update this message with. If ``None`` is passed then
11601160
the view is removed.
11611161
delete_after: Optional[:class:`float`]
@@ -1486,7 +1486,7 @@ async def edit(
14861486
file: File = MISSING,
14871487
files: list[File] = MISSING,
14881488
attachments: list[Attachment] = MISSING,
1489-
view: View | None = MISSING,
1489+
view: BaseView | None = MISSING,
14901490
allowed_mentions: AllowedMentions | None = None,
14911491
delete_after: float | None = None,
14921492
suppress: bool | None = MISSING,
@@ -1515,7 +1515,7 @@ async def edit(
15151515
allowed_mentions: :class:`AllowedMentions`
15161516
Controls the mentions being processed in this message.
15171517
See :meth:`.abc.Messageable.send` for more information.
1518-
view: Optional[:class:`~discord.ui.View`]
1518+
view: Optional[:class:`~discord.ui.BaseView`]
15191519
The updated view to update this message with. If ``None`` is passed then
15201520
the view is removed.
15211521
delete_after: Optional[:class:`float`]

discord/message.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
from .types.snowflake import SnowflakeList
9393
from .types.threads import ThreadArchiveDuration
9494
from .types.user import User as UserPayload
95-
from .ui.view import View
95+
from .ui.view import BaseView
9696
from .user import User
9797

9898
MR = TypeVar("MR", bound="MessageReference")
@@ -1660,7 +1660,7 @@ async def edit(
16601660
suppress: bool = ...,
16611661
delete_after: float | None = ...,
16621662
allowed_mentions: AllowedMentions | None = ...,
1663-
view: View | None = ...,
1663+
view: BaseView | None = ...,
16641664
) -> Message: ...
16651665

16661666
async def edit(
@@ -1674,7 +1674,7 @@ async def edit(
16741674
suppress: bool = MISSING,
16751675
delete_after: float | None = None,
16761676
allowed_mentions: AllowedMentions | None = MISSING,
1677-
view: View | None = MISSING,
1677+
view: BaseView | None = MISSING,
16781678
) -> Message:
16791679
"""|coro|
16801680
@@ -1723,7 +1723,7 @@ async def edit(
17231723
are used instead.
17241724
17251725
.. versionadded:: 1.4
1726-
view: Optional[:class:`~discord.ui.View`]
1726+
view: Optional[:class:`~discord.ui.BaseView`]
17271727
The updated view to update this message with. If ``None`` is passed then
17281728
the view is removed.
17291729
@@ -2412,7 +2412,7 @@ async def edit(self, **fields: Any) -> Message | None:
24122412
to the object, otherwise it uses the attributes set in :attr:`~discord.Client.allowed_mentions`.
24132413
If no object is passed at all then the defaults given by :attr:`~discord.Client.allowed_mentions`
24142414
are used instead.
2415-
view: Optional[:class:`~discord.ui.View`]
2415+
view: Optional[:class:`~discord.ui.BaseView`]
24162416
The updated view to update this message with. If ``None`` is passed then
24172417
the view is removed.
24182418

discord/state.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
from .sticker import GuildSticker
7272
from .threads import Thread, ThreadMember
7373
from .ui.modal import Modal, ModalStore
74-
from .ui.view import View, ViewStore
74+
from .ui.view import BaseView, ViewStore
7575
from .user import ClientUser, User
7676

7777
if TYPE_CHECKING:
@@ -399,17 +399,17 @@ def store_sticker(self, guild: Guild, data: GuildStickerPayload) -> GuildSticker
399399
self._stickers[sticker_id] = sticker = GuildSticker(state=self, data=data)
400400
return sticker
401401

402-
def store_view(self, view: View, message_id: int | None = None) -> None:
402+
def store_view(self, view: BaseView, message_id: int | None = None) -> None:
403403
self._view_store.add_view(view, message_id)
404404

405405
def store_modal(self, modal: Modal, message_id: int) -> None:
406406
self._modal_store.add_modal(modal, message_id)
407407

408-
def prevent_view_updates_for(self, message_id: int) -> View | None:
408+
def prevent_view_updates_for(self, message_id: int) -> BaseView | None:
409409
return self._view_store.remove_message_tracking(message_id)
410410

411411
@property
412-
def persistent_views(self) -> Sequence[View]:
412+
def persistent_views(self) -> Sequence[BaseView]:
413413
return self._view_store.persistent_views
414414

415415
@property

discord/ui/action_row.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
from ..emoji import AppEmoji, GuildEmoji
2222
from ..partial_emoji import PartialEmoji, _EmojiTag
2323
from ..types.components import ActionRow as ActionRowPayload
24-
from .view import View
24+
from .view import DesignerView
2525

2626

2727
A = TypeVar("A", bound="ActionRow")
28-
V = TypeVar("V", bound="View", covariant=True)
28+
V = TypeVar("V", bound="DesignerView", covariant=True)
2929

3030

3131
class ActionRow(Item[V]):

discord/ui/button.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@
4141

4242
if TYPE_CHECKING:
4343
from ..emoji import AppEmoji, GuildEmoji
44-
from .view import View
44+
from .view import BaseView
4545

4646
B = TypeVar("B", bound="Button")
47-
V = TypeVar("V", bound="View", covariant=True)
47+
V = TypeVar("V", bound="BaseView", covariant=True)
4848

4949

5050
class Button(Item[V]):
@@ -298,7 +298,7 @@ def button(
298298
"""A decorator that attaches a button to a component.
299299
300300
The function being decorated should have three parameters, ``self`` representing
301-
the :class:`discord.ui.View`, the :class:`discord.ui.Button` being pressed and
301+
the :class:`discord.ui.View`, :class:`discord.ui.ActionRow` or :class:`discord.ui.Section`, the :class:`discord.ui.Button` being pressed, and
302302
the :class:`discord.Interaction` you receive.
303303
304304
.. note::

discord/ui/container.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
from typing_extensions import Self
2626

2727
from ..types.components import ContainerComponent as ContainerComponentPayload
28-
from .view import View
28+
from .view import DesignerView
2929

3030

3131
C = TypeVar("C", bound="Container")
32-
V = TypeVar("V", bound="View", covariant=True)
32+
V = TypeVar("V", bound="DesignerView", covariant=True)
3333

3434

3535
class Container(Item[V]):

discord/ui/file.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111

1212
if TYPE_CHECKING:
1313
from ..types.components import FileComponent as FileComponentPayload
14-
from .view import View
14+
from .view import DesignerView
1515

1616

1717
F = TypeVar("F", bound="File")
18-
V = TypeVar("V", bound="View", covariant=True)
18+
V = TypeVar("V", bound="DesignerView", covariant=True)
1919

2020

2121
class File(Item[V]):

0 commit comments

Comments
 (0)