Skip to content

Commit dc2bf6d

Browse files
authored
Merge branch 'master' into chore/docs-cleanup
2 parents d245627 + 28b4682 commit dc2bf6d

8 files changed

Lines changed: 64 additions & 34 deletions

File tree

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ jobs:
215215
python3 -m build --sdist
216216
python3 -m build --wheel
217217
- name: "Create GitHub Release"
218-
uses: softprops/action-gh-release@v2.6.1
218+
uses: softprops/action-gh-release@b4309332981a82ec1c5618f44dd2e27cc8bfbfda # v3.0.0
219219
id: gh-release
220220
with:
221221
tag_name: "v${{ inputs.version }}"

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ These changes are available on the `master` branch, but have not yet been releas
2727
([#3181](https://github.com/Pycord-Development/pycord/pull/3181))
2828
- Fixed internal use of deprecated \_PayloadLike dict operations.
2929
([#3189](https://github.com/Pycord-Development/pycord/pull/3189))
30+
- Fixed incorrect type hints for `MessagePinIterator`.
31+
([#3178](https://github.com/Pycord-Development/pycord/pull/3178))
3032

3133
### Deprecated
3234

discord/abc.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
Iterable,
3636
Protocol,
3737
Sequence,
38+
TypeAlias,
3839
TypeVar,
3940
Union,
4041
overload,
@@ -97,10 +98,15 @@
9798
from .ui.view import BaseView
9899
from .user import ClientUser
99100

100-
PartialMessageableChannel = Union[
101-
TextChannel, VoiceChannel, StageChannel, Thread, DMChannel, PartialMessageable
102-
]
103-
MessageableChannel = Union[PartialMessageableChannel, GroupChannel]
101+
PartialMessageableChannel: TypeAlias = (
102+
TextChannel
103+
| VoiceChannel
104+
| StageChannel
105+
| Thread
106+
| DMChannel
107+
| PartialMessageable
108+
)
109+
MessageableChannel: TypeAlias = PartialMessageableChannel | GroupChannel
104110
SnowflakeTime = Union["Snowflake", datetime]
105111

106112
from .voice import VoiceClient, VoiceProtocol

discord/iterators.py

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@
3939
Union,
4040
)
4141

42+
from typing_extensions import deprecated, override
43+
4244
from .audit_logs import AuditLogEntry
4345
from .errors import NoMoreItems
4446
from .object import Object
45-
from .utils import maybe_coroutine, snowflake_time, time_snowflake, warn_deprecated
47+
from .utils import maybe_coroutine, snowflake_time, time_snowflake
4648

4749
__all__ = (
4850
"ReactionIterator",
@@ -53,12 +55,13 @@
5355
"ScheduledEventSubscribersIterator",
5456
"EntitlementIterator",
5557
"SubscriptionIterator",
58+
"MessagePinIterator",
5659
)
5760

5861
if TYPE_CHECKING:
59-
from .abc import Snowflake
60-
from .channel import MessageableChannel
62+
from .abc import MessageableChannel, Snowflake
6163
from .guild import BanEntry, Guild
64+
from .http import HTTPClient
6265
from .member import Member
6366
from .message import Message, MessagePin
6467
from .monetization import Entitlement, Subscription
@@ -1210,9 +1213,13 @@ def __init__(
12101213
limit: int | None,
12111214
before: Snowflake | datetime.datetime | None = None,
12121215
):
1213-
self._channel = channel
1214-
self.limit = limit
1215-
self.http = channel._state.http
1216+
self._channel: MessageableChannel = channel
1217+
self.channel: MessageableChannel | Object | None = None
1218+
1219+
self.limit: int | None = limit
1220+
self.http: HTTPClient = (
1221+
channel._state.http # pyright: ignore[reportPrivateUsage]
1222+
)
12161223

12171224
self.before: str | None
12181225
if before is None:
@@ -1224,11 +1231,10 @@ def __init__(
12241231

12251232
self.update_before: Callable[[MessagePinPayload], str] = self.get_last_pinned
12261233

1227-
self.endpoint = self.http.pins_from
1228-
12291234
self.queue: asyncio.Queue[MessagePin] = asyncio.Queue()
12301235
self.has_more: bool = True
12311236

1237+
@override
12321238
async def next(self) -> MessagePin:
12331239
if self.queue.empty():
12341240
await self.fill_queue()
@@ -1246,12 +1252,16 @@ async def fill_queue(self) -> None:
12461252
if not self.has_more:
12471253
raise NoMoreItems()
12481254

1249-
if not hasattr(self, "channel"):
1250-
channel = await self._channel._get_channel()
1255+
if self.channel is None:
1256+
channel = (
1257+
await self._channel._get_channel() # pyright: ignore[reportPrivateUsage]
1258+
)
12511259
self.channel = channel
12521260

12531261
limit = 50 if self.limit is None else min(self.limit, 50)
1254-
data = await self.endpoint(self.channel.id, before=self.before, limit=limit)
1262+
data = await self.http.pins_from(
1263+
self.channel.id, before=self.before, limit=limit
1264+
)
12551265

12561266
pins: list[MessagePinPayload] = data.get("items", [])
12571267
for d in pins:
@@ -1269,17 +1279,25 @@ async def fill_queue(self) -> None:
12691279
def create_pin(self, data: MessagePinPayload) -> MessagePin:
12701280
from .message import MessagePin
12711281

1272-
return MessagePin(state=self.channel._state, channel=self.channel, data=data)
1282+
if self.channel is None:
1283+
raise RuntimeError("Channel is None, cannot create pin")
1284+
1285+
if isinstance(self.channel, Object):
1286+
raise RuntimeError("Cannot create pin for Object channel")
1287+
1288+
return MessagePin(
1289+
state=self.channel._state, # pyright: ignore[reportPrivateUsage]
1290+
channel=self.channel,
1291+
data=data,
1292+
)
12731293

12741294
async def retrieve_inner(self) -> list[Message]:
12751295
pins = await self.flatten()
12761296
return [p.message for p in pins]
12771297

1278-
def __await__(self) -> Generator[Any, Any, MessagePin]:
1279-
warn_deprecated(
1280-
f"Messageable.pins() returning a list of Message",
1281-
since="2.7",
1282-
removed="3.0",
1283-
reference="The documentation of pins()",
1284-
)
1298+
@deprecated(
1299+
"Messageable.pins() returning a list of Message is deprecated since version 2.7 and will be removed in 2.9."
1300+
+ " See the documentation of Messageable.pins() for more information."
1301+
)
1302+
def __await__(self) -> Generator[Any, Any, list[Message]]:
12851303
return self.retrieve_inner().__await__()

discord/member.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -663,9 +663,8 @@ def display_name(self) -> str:
663663
def display_avatar(self) -> Asset:
664664
"""Returns the member's display avatar.
665665
666-
For regular members this is just their avatar, but
667-
if they have a guild specific avatar then that
668-
is returned instead.
666+
Returns the user's guild avatar.
667+
If the user does not have a guild avatar, their global avatar is returned instead.
669668
670669
.. versionadded:: 2.0
671670
"""
@@ -688,9 +687,8 @@ def guild_avatar(self) -> Asset | None:
688687
def display_avatar_decoration(self) -> Asset | None:
689688
"""Returns the member's displayed avatar decoration.
690689
691-
For regular members this is just their avatar decoration, but
692-
if they have a guild specific avatar decoration then that
693-
is returned instead.
690+
Returns the user's guild avatar decoration.
691+
If the user does not have a guild avatar decoration, their global avatar decoration is returned instead.
694692
695693
.. versionadded:: 2.8
696694
"""
@@ -713,9 +711,8 @@ def guild_avatar_decoration(self) -> Asset | None:
713711
def display_banner(self) -> Asset | None:
714712
"""Returns the member's display banner.
715713
716-
For regular members this is just their banner, but
717-
if they have a guild specific banner then that
718-
is returned instead.
714+
Returns the user's guild banner.
715+
If the user does not have a guild banner, their global banner is returned instead.
719716
720717
.. versionadded:: 2.7
721718
"""

discord/message.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
__all__ = (
103103
"Attachment",
104104
"Message",
105+
"MessagePin",
105106
"PartialMessage",
106107
"MessageReference",
107108
"MessageCall",

discord/user.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,8 @@ def default_avatar(self) -> Asset:
251251
def display_avatar(self) -> Asset:
252252
"""Returns the user's display avatar.
253253
254-
For regular users this is just their default avatar or uploaded avatar.
254+
Returns the user's uploaded avatar.
255+
If the user has not uploaded any avatar, their default avatar is returned instead.
255256
256257
.. versionadded:: 2.0
257258
"""

docs/api/models.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ Messages
8989
.. autoclass:: Message()
9090
:members:
9191

92+
.. attributetable:: MessagePin
93+
94+
.. autoclass:: MessagePin()
95+
:members:
96+
9297
.. attributetable:: MessageSnapshot
9398

9499
.. autoclass:: MessageSnapshot()

0 commit comments

Comments
 (0)