@@ -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:
@@ -424,12 +437,6 @@ class SnowflakeList(array.array):
424437
425438 __slots__ = ()
426439
427- if TYPE_CHECKING :
428-
429- def __init__ (self , data : Iterable [int ], * , is_sorted : bool = False ): ...
430- def __iter__ (self ) -> Iterator [int ]: ...
431- def __getitem__ (self , i : int ) -> int : ...
432-
433440 def __new__ (cls , data : Iterable [int ], * , is_sorted : bool = False ):
434441 return super ().__new__ (cls , "Q" , data if is_sorted else sorted (data ))
435442
0 commit comments