Skip to content

Commit 063a096

Browse files
committed
🐛 Use mypy suggested method for array.array genericness
Signed-off-by: Paillat-dev <[email protected]>
1 parent 5391fa0 commit 063a096

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

discord/utils/private.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,20 @@ async def sane_wait_for(futures: Iterable[Awaitable[T]], *, timeout: float) -> s
410410
return done
411411

412412

413-
class SnowflakeList(array.array):
413+
# array.array is generic only since Python 3.12
414+
# ref: https://docs.python.org/3/whatsnew/3.12.html#array
415+
# We use the method suggested by mypy
416+
# ref: https://mypy.readthedocs.io/en/stable/runtime_troubles.html#using-classes-that-are-generic-in-stubs-but-not-at-runtime
417+
418+
if TYPE_CHECKING:
419+
SnowflakeListBase = array.array[int]
420+
else:
421+
if sys.version_info >= (3, 12):
422+
SnowflakeListBase = array.array[int]
423+
else:
424+
SnowflakeListBase = array.array
425+
426+
class SnowflakeList(SnowflakeListBase):
414427
"""Internal data storage class to efficiently store a list of snowflakes.
415428
416429
This should have the following characteristics:

0 commit comments

Comments
 (0)