-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
29 lines (22 loc) · 867 Bytes
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from dataclasses import dataclass, field
from functools import wraps
from typing import Callable, Optional, Protocol
@dataclass(slots=True)
class Extraction:
draw: tuple[int, ...]
extra: Optional[tuple[int, ...]] = field(default=None)
def validate_draw_params(func) -> Callable:
'''
Decorator to validate draw parameters, to assure the size is within
the range of 1 to max_num. This to avoid repetitions in the draw.
'''
@wraps(func)
def wrapper(self, size: int, max_num: int, *args, **kwargs):
if not 0 < size <= max_num:
raise ValueError(
f"Invalid draw parameters: size={size}, max_num={max_num}")
return func(self, size, max_num, *args, **kwargs)
return wrapper
class DrawMethod(Protocol):
__name__: str
def __call__(self, size: int, max_num: int) -> tuple[int]: ...