Skip to content

Commit f1c5f64

Browse files
committed
🏷️ Type Asset construction methods better
1 parent 5ea9120 commit f1c5f64

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

discord/asset.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,15 @@
3434
from . import utils
3535
from .errors import DiscordException, InvalidArgument
3636

37+
if TYPE_CHECKING:
38+
from .app.state import ConnectionState
39+
3740
__all__ = ("Asset",)
3841

3942
if TYPE_CHECKING:
4043
ValidStaticFormatTypes = Literal["webp", "jpeg", "jpg", "png"]
4144
ValidAssetFormatTypes = Literal["webp", "jpeg", "jpg", "png", "gif"]
42-
from .state import ConnectionState
45+
from .app.state import ConnectionState
4346

4447

4548
VALID_STATIC_FORMATS = frozenset({"jpeg", "jpg", "webp", "png"})
@@ -172,7 +175,7 @@ def __init__(self, state, *, url: str, key: str, animated: bool = False):
172175
self._key = key
173176

174177
@classmethod
175-
def _from_default_avatar(cls, state, index: int) -> Asset:
178+
def _from_default_avatar(cls, state: ConnectionState, index: int) -> Asset:
176179
return cls(
177180
state,
178181
url=f"{cls.BASE}/embed/avatars/{index}.png",
@@ -181,7 +184,7 @@ def _from_default_avatar(cls, state, index: int) -> Asset:
181184
)
182185

183186
@classmethod
184-
def _from_avatar(cls, state, user_id: int, avatar: str) -> Asset:
187+
def _from_avatar(cls, state: ConnectionState, user_id: int, avatar: str) -> Asset:
185188
animated = avatar.startswith("a_")
186189
format = "gif" if animated else "png"
187190
return cls(
@@ -192,7 +195,7 @@ def _from_avatar(cls, state, user_id: int, avatar: str) -> Asset:
192195
)
193196

194197
@classmethod
195-
def _from_avatar_decoration(cls, state, user_id: int, avatar_decoration: str) -> Asset:
198+
def _from_avatar_decoration(cls, state: ConnectionState, user_id: int, avatar_decoration: str) -> Asset:
196199
animated = avatar_decoration.startswith("a_")
197200
endpoint = (
198201
"avatar-decoration-presets"
@@ -232,7 +235,7 @@ def _from_user_primary_guild_tag(cls, state: ConnectionState, identity_guild_id:
232235
)
233236

234237
@classmethod
235-
def _from_guild_avatar(cls, state, guild_id: int, member_id: int, avatar: str) -> Asset:
238+
def _from_guild_avatar(cls, state: ConnectionState, guild_id: int, member_id: int, avatar: str) -> Asset:
236239
animated = avatar.startswith("a_")
237240
format = "gif" if animated else "png"
238241
return cls(
@@ -243,7 +246,7 @@ def _from_guild_avatar(cls, state, guild_id: int, member_id: int, avatar: str) -
243246
)
244247

245248
@classmethod
246-
def _from_guild_banner(cls, state, guild_id: int, member_id: int, banner: str) -> Asset:
249+
def _from_guild_banner(cls, state: ConnectionState, guild_id: int, member_id: int, banner: str) -> Asset:
247250
animated = banner.startswith("a_")
248251
format = "gif" if animated else "png"
249252
return cls(
@@ -254,7 +257,7 @@ def _from_guild_banner(cls, state, guild_id: int, member_id: int, banner: str) -
254257
)
255258

256259
@classmethod
257-
def _from_icon(cls, state, object_id: int, icon_hash: str, path: str) -> Asset:
260+
def _from_icon(cls, state: ConnectionState, object_id: int, icon_hash: str, path: str) -> Asset:
258261
return cls(
259262
state,
260263
url=f"{cls.BASE}/{path}-icons/{object_id}/{icon_hash}.png?size=1024",
@@ -263,7 +266,7 @@ def _from_icon(cls, state, object_id: int, icon_hash: str, path: str) -> Asset:
263266
)
264267

265268
@classmethod
266-
def _from_cover_image(cls, state, object_id: int, cover_image_hash: str) -> Asset:
269+
def _from_cover_image(cls, state: ConnectionState, object_id: int, cover_image_hash: str) -> Asset:
267270
return cls(
268271
state,
269272
url=f"{cls.BASE}/app-assets/{object_id}/store/{cover_image_hash}.png?size=1024",
@@ -282,7 +285,7 @@ def _from_collectible(cls, state: ConnectionState, asset: str, animated: bool =
282285
)
283286

284287
@classmethod
285-
def _from_guild_image(cls, state, guild_id: int, image: str, path: str) -> Asset:
288+
def _from_guild_image(cls, state: ConnectionState, guild_id: int, image: str, path: str) -> Asset:
286289
animated = False
287290
format = "png"
288291
if path == "banners":
@@ -297,7 +300,7 @@ def _from_guild_image(cls, state, guild_id: int, image: str, path: str) -> Asset
297300
)
298301

299302
@classmethod
300-
def _from_guild_icon(cls, state, guild_id: int, icon_hash: str) -> Asset:
303+
def _from_guild_icon(cls, state: ConnectionState, guild_id: int, icon_hash: str) -> Asset:
301304
animated = icon_hash.startswith("a_")
302305
format = "gif" if animated else "png"
303306
return cls(
@@ -308,7 +311,7 @@ def _from_guild_icon(cls, state, guild_id: int, icon_hash: str) -> Asset:
308311
)
309312

310313
@classmethod
311-
def _from_sticker_banner(cls, state, banner: int) -> Asset:
314+
def _from_sticker_banner(cls, state: ConnectionState, banner: int) -> Asset:
312315
return cls(
313316
state,
314317
url=f"{cls.BASE}/app-assets/710982414301790216/store/{banner}.png",
@@ -317,7 +320,7 @@ def _from_sticker_banner(cls, state, banner: int) -> Asset:
317320
)
318321

319322
@classmethod
320-
def _from_user_banner(cls, state, user_id: int, banner_hash: str) -> Asset:
323+
def _from_user_banner(cls, state: ConnectionState, user_id: int, banner_hash: str) -> Asset:
321324
animated = banner_hash.startswith("a_")
322325
format = "gif" if animated else "png"
323326
return cls(
@@ -328,7 +331,7 @@ def _from_user_banner(cls, state, user_id: int, banner_hash: str) -> Asset:
328331
)
329332

330333
@classmethod
331-
def _from_scheduled_event_image(cls, state, event_id: int, cover_hash: str) -> Asset:
334+
def _from_scheduled_event_image(cls, state: ConnectionState, event_id: int, cover_hash: str) -> Asset:
332335
return cls(
333336
state,
334337
url=f"{cls.BASE}/guild-events/{event_id}/{cover_hash}.png",
@@ -337,7 +340,7 @@ def _from_scheduled_event_image(cls, state, event_id: int, cover_hash: str) -> A
337340
)
338341

339342
@classmethod
340-
def _from_soundboard_sound(cls, state, sound_id: int) -> Asset:
343+
def _from_soundboard_sound(cls, state: ConnectionState, sound_id: int) -> Asset:
341344
return cls(
342345
state,
343346
url=f"{cls.BASE}/soundboard-sounds/{sound_id}",

0 commit comments

Comments
 (0)