41
41
Callable ,
42
42
TypeVar ,
43
43
Protocol ,
44
+ overload ,
44
45
TYPE_CHECKING ,
45
- runtime_checkable
46
+ runtime_checkable , Generic ,
46
47
)
47
48
48
49
import os
69
70
from operator import attrgetter
70
71
71
72
from .errors import InvalidArgument
72
- from .enums import TimestampStyle
73
+ from .enums import TimestampStyle , InviteTargetType
73
74
74
75
if TYPE_CHECKING :
75
76
from typing_extensions import ParamSpec , TypeGuard , Self
86
87
87
88
T = TypeVar ('T' )
88
89
R = TypeVar ('R' )
90
+ _IterableClassType = TypeVar ('_IterableClassType' , bound = Type [Iterable ])
89
91
_Iterable = TypeVar ('_Iterable' , bound = Iterable )
90
92
MaybeAwaitable = Union [Awaitable [T ], T ]
91
93
@@ -508,17 +510,27 @@ async def countdown(ctx, seconds: int):
508
510
509
511
510
512
async def create_voice_activity (channel : VoiceChannel , target_application_id : int , ** kwargs ):
511
- return await channel .create_invite (targe_type = 2 , target_application_id = target_application_id , ** kwargs )
512
-
513
-
514
- def _unique (iterable : _Iterable [T ]) -> _Iterable [T ]:
513
+ return await channel .create_invite (
514
+ target_type = InviteTargetType .embedded_application ,
515
+ target_application_id = target_application_id ,
516
+ ** kwargs
517
+ )
518
+
519
+ @overload
520
+ def _unique (iterable : _Iterable [T ]) -> _Iterable [T ]: ...
521
+
522
+ @overload
523
+ def _unique (iterable : _Iterable [T ], return_type : _IterableClassType ) -> _IterableClassType [T ]: ...
524
+ # idk why this typing this doesn't work
525
+
526
+ def _unique (
527
+ iterable : _Iterable [T ],
528
+ return_type : Optional [_IterableClassType ] = None
529
+ ) -> Union [_Iterable [T ], _IterableClassType [T ]]:
515
530
seen = set ()
516
531
adder = seen .add
517
- origin_type = type (iterable )
518
- if origin_type not in {list , tuple , set }:
519
- origin_type = list
520
- return origin_type ([x for x in iterable if not (x in seen or adder (x ))])
521
-
532
+ return_type = return_type or type (iterable )
533
+ return return_type (x for x in iterable if not (x in seen or adder (x )))
522
534
523
535
def _get_as_snowflake (data : Dict [str , Any ], key : str ) -> Optional [int ]:
524
536
try :
@@ -532,7 +544,7 @@ def _get_as_snowflake(data: Dict[str, Any], key: str) -> Optional[int]:
532
544
def _get_mime_type_for_image (data : bytes ) -> str :
533
545
if data .startswith (b'\x89 \x50 \x4E \x47 \x0D \x0A \x1A \x0A ' ):
534
546
return 'image/png'
535
- elif data [0 :3 ] == b'\xff \xd8 \xff ' or data [6 :10 ] in (b'JFIF' , b'Exif' ):
547
+ elif data [:3 ] == b'\xff \xd8 \xff ' or data [6 :10 ] in (b'JFIF' , b'Exif' ):
536
548
return 'image/jpeg'
537
549
elif data .startswith ((b'\x47 \x49 \x46 \x38 \x37 \x61 ' , b'\x47 \x49 \x46 \x38 \x39 \x61 ' )):
538
550
return 'image/gif'
0 commit comments