|
23 | 23 | import types |
24 | 24 | import warnings |
25 | 25 | from pathlib import Path |
26 | | -from typing import Any, Union, overload, Sequence |
| 26 | +from typing import Any, Sequence, Union, overload |
27 | 27 |
|
28 | 28 | import numpy as np |
29 | 29 | import numpy.typing as npt |
@@ -328,27 +328,27 @@ def random_int(self, *args: int) -> int: |
328 | 328 | types = ",".join([type(a).__name__ for a in args]) |
329 | 329 | raise TypeError(f"No matching overloads found for Sketch.random_int({types})") |
330 | 330 |
|
331 | | - def random_choice(self, objects: list[Any]) -> Any: |
| 331 | + def random_choice(self, seq: Sequence[Any]) -> Any: |
332 | 332 | """$class_Sketch_random_choice""" |
333 | | - if len(objects): |
334 | | - return objects[self._rng.integers(0, len(objects))] |
| 333 | + if len(seq): |
| 334 | + return seq[self._rng.integers(0, len(seq))] |
335 | 335 | else: |
336 | 336 | return None |
337 | 337 |
|
338 | 338 | def random_sample( |
339 | | - self, objects: list[Any], size: int = 1, replace: bool = True |
340 | | - ) -> list[Any]: |
| 339 | + self, seq: Sequence[Any], size: int = 1, replace: bool = True |
| 340 | + ) -> Sequence[Any]: |
341 | 341 | """$class_Sketch_random_sample""" |
342 | | - if len(objects): |
343 | | - if isinstance(objects, types.GeneratorType): |
344 | | - objects = list(objects) |
345 | | - indices = self._rng.choice(range(len(objects)), size=size, replace=replace) |
346 | | - if not isinstance(objects, list): |
| 342 | + if len(seq): |
| 343 | + if isinstance(seq, types.GeneratorType): |
| 344 | + seq = list(seq) |
| 345 | + indices = self._rng.choice(range(len(seq)), size=size, replace=replace) |
| 346 | + if not isinstance(seq, list): |
347 | 347 | try: |
348 | | - return objects[indices] |
| 348 | + return seq[indices] |
349 | 349 | except: |
350 | 350 | pass |
351 | | - return [objects[idx] for idx in indices] |
| 351 | + return [seq[idx] for idx in indices] |
352 | 352 | else: |
353 | 353 | return [] |
354 | 354 |
|
|
0 commit comments