@@ -410,7 +410,20 @@ async def sane_wait_for(futures: Iterable[Awaitable[T]], *, timeout: float) -> s
410
410
return done
411
411
412
412
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 ):
414
427
"""Internal data storage class to efficiently store a list of snowflakes.
415
428
416
429
This should have the following characteristics:
@@ -424,12 +437,6 @@ class SnowflakeList(array.array):
424
437
425
438
__slots__ = ()
426
439
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
-
433
440
def __new__ (cls , data : Iterable [int ], * , is_sorted : bool = False ):
434
441
return super ().__new__ (cls , "Q" , data if is_sorted else sorted (data ))
435
442
@@ -445,6 +452,7 @@ def has(self, element: int) -> bool:
445
452
i = bisect_left (self , element )
446
453
return i != len (self ) and self [i ] == element
447
454
455
+ ee = SnowflakeList ()
448
456
449
457
def copy_doc (original : Callable [..., object ]) -> Callable [[T ], T ]:
450
458
def decorator (overridden : T ) -> T :
0 commit comments