3939 Union ,
4040)
4141
42+ from typing_extensions import deprecated , override
43+
4244from .audit_logs import AuditLogEntry
4345from .errors import NoMoreItems
4446from .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" ,
5355 "ScheduledEventSubscribersIterator" ,
5456 "EntitlementIterator" ,
5557 "SubscriptionIterator" ,
58+ "MessagePinIterator" ,
5659)
5760
5861if 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__ ()
0 commit comments