dycw-utilities 0.133.7__py3-none-any.whl → 0.134.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {dycw_utilities-0.133.7.dist-info → dycw_utilities-0.134.1.dist-info}/METADATA +1 -1
- {dycw_utilities-0.133.7.dist-info → dycw_utilities-0.134.1.dist-info}/RECORD +40 -39
- utilities/__init__.py +1 -1
- utilities/arq.py +13 -20
- utilities/asyncio.py +59 -74
- utilities/atools.py +10 -13
- utilities/cachetools.py +11 -17
- utilities/click.py +31 -51
- utilities/concurrent.py +7 -10
- utilities/dataclasses.py +69 -91
- utilities/enum.py +24 -21
- utilities/eventkit.py +34 -48
- utilities/functions.py +133 -168
- utilities/functools.py +18 -19
- utilities/hypothesis.py +34 -44
- utilities/iterables.py +165 -179
- utilities/luigi.py +3 -15
- utilities/memory_profiler.py +11 -15
- utilities/more_itertools.py +85 -94
- utilities/operator.py +5 -7
- utilities/optuna.py +6 -6
- utilities/pathlib.py +1 -0
- utilities/period.py +7 -9
- utilities/polars.py +5 -16
- utilities/pqdm.py +7 -8
- utilities/pudb.py +62 -0
- utilities/pydantic.py +2 -4
- utilities/pytest.py +14 -23
- utilities/python_dotenv.py +5 -9
- utilities/random.py +2 -3
- utilities/redis.py +163 -181
- utilities/slack_sdk.py +2 -2
- utilities/sqlalchemy.py +4 -14
- utilities/timer.py +6 -0
- utilities/typed_settings.py +7 -10
- utilities/types.py +10 -94
- utilities/typing.py +32 -43
- utilities/uuid.py +1 -0
- {dycw_utilities-0.133.7.dist-info → dycw_utilities-0.134.1.dist-info}/WHEEL +0 -0
- {dycw_utilities-0.133.7.dist-info → dycw_utilities-0.134.1.dist-info}/licenses/LICENSE +0 -0
utilities/hypothesis.py
CHANGED
@@ -10,16 +10,7 @@ from pathlib import Path
|
|
10
10
|
from re import search
|
11
11
|
from string import ascii_letters, ascii_lowercase, ascii_uppercase, digits, printable
|
12
12
|
from subprocess import check_call
|
13
|
-
from typing import
|
14
|
-
TYPE_CHECKING,
|
15
|
-
Any,
|
16
|
-
Literal,
|
17
|
-
TypeVar,
|
18
|
-
assert_never,
|
19
|
-
cast,
|
20
|
-
overload,
|
21
|
-
override,
|
22
|
-
)
|
13
|
+
from typing import TYPE_CHECKING, Any, Literal, assert_never, cast, overload, override
|
23
14
|
|
24
15
|
import hypothesis.strategies
|
25
16
|
from hypothesis import HealthCheck, Phase, Verbosity, assume, settings
|
@@ -121,7 +112,6 @@ if TYPE_CHECKING:
|
|
121
112
|
from utilities.types import Number, TimeZoneLike
|
122
113
|
|
123
114
|
|
124
|
-
_T = TypeVar("_T")
|
125
115
|
type MaybeSearchStrategy[_T] = _T | SearchStrategy[_T]
|
126
116
|
type Shape = int | tuple[int, ...]
|
127
117
|
|
@@ -288,48 +278,48 @@ def dates(
|
|
288
278
|
|
289
279
|
|
290
280
|
@overload
|
291
|
-
def draw2(
|
281
|
+
def draw2[T](
|
292
282
|
data_or_draw: DataObject | DrawFn,
|
293
|
-
maybe_strategy: MaybeSearchStrategy[
|
283
|
+
maybe_strategy: MaybeSearchStrategy[T],
|
294
284
|
/,
|
295
285
|
*,
|
296
286
|
sentinel: bool = False,
|
297
|
-
) ->
|
287
|
+
) -> T: ...
|
298
288
|
@overload
|
299
|
-
def draw2(
|
289
|
+
def draw2[T](
|
300
290
|
data_or_draw: DataObject | DrawFn,
|
301
|
-
maybe_strategy: MaybeSearchStrategy[
|
302
|
-
default: SearchStrategy[
|
291
|
+
maybe_strategy: MaybeSearchStrategy[T | None | Sentinel],
|
292
|
+
default: SearchStrategy[T | None],
|
303
293
|
/,
|
304
294
|
*,
|
305
295
|
sentinel: Literal[True],
|
306
|
-
) ->
|
296
|
+
) -> T | None: ...
|
307
297
|
@overload
|
308
|
-
def draw2(
|
298
|
+
def draw2[T](
|
309
299
|
data_or_draw: DataObject | DrawFn,
|
310
|
-
maybe_strategy: MaybeSearchStrategy[
|
311
|
-
default: SearchStrategy[
|
300
|
+
maybe_strategy: MaybeSearchStrategy[T | None],
|
301
|
+
default: SearchStrategy[T],
|
312
302
|
/,
|
313
303
|
*,
|
314
304
|
sentinel: Literal[False] = False,
|
315
|
-
) ->
|
305
|
+
) -> T: ...
|
316
306
|
@overload
|
317
|
-
def draw2(
|
307
|
+
def draw2[T](
|
318
308
|
data_or_draw: DataObject | DrawFn,
|
319
|
-
maybe_strategy: MaybeSearchStrategy[
|
320
|
-
default: SearchStrategy[
|
309
|
+
maybe_strategy: MaybeSearchStrategy[T | None | Sentinel],
|
310
|
+
default: SearchStrategy[T] | None = None,
|
321
311
|
/,
|
322
312
|
*,
|
323
313
|
sentinel: bool = False,
|
324
|
-
) ->
|
325
|
-
def draw2(
|
314
|
+
) -> T | None: ...
|
315
|
+
def draw2[T](
|
326
316
|
data_or_draw: DataObject | DrawFn,
|
327
|
-
maybe_strategy: MaybeSearchStrategy[
|
328
|
-
default: SearchStrategy[
|
317
|
+
maybe_strategy: MaybeSearchStrategy[T | None | Sentinel],
|
318
|
+
default: SearchStrategy[T | None] | None = None,
|
329
319
|
/,
|
330
320
|
*,
|
331
321
|
sentinel: bool = False,
|
332
|
-
) ->
|
322
|
+
) -> T | None:
|
333
323
|
"""Draw an element from a strategy, unless you require it to be non-nullable."""
|
334
324
|
draw = data_or_draw.draw if isinstance(data_or_draw, DataObject) else data_or_draw
|
335
325
|
if isinstance(maybe_strategy, SearchStrategy):
|
@@ -628,15 +618,15 @@ def int64s(
|
|
628
618
|
|
629
619
|
|
630
620
|
@composite
|
631
|
-
def lists_fixed_length(
|
621
|
+
def lists_fixed_length[T](
|
632
622
|
draw: DrawFn,
|
633
|
-
strategy: SearchStrategy[
|
623
|
+
strategy: SearchStrategy[T],
|
634
624
|
size: MaybeSearchStrategy[int],
|
635
625
|
/,
|
636
626
|
*,
|
637
627
|
unique: MaybeSearchStrategy[bool] = False,
|
638
628
|
sorted: MaybeSearchStrategy[bool] = False, # noqa: A002
|
639
|
-
) -> list[
|
629
|
+
) -> list[T]:
|
640
630
|
"""Strategy for generating lists of a fixed length."""
|
641
631
|
size_ = draw2(draw, size)
|
642
632
|
elements = draw(
|
@@ -737,18 +727,18 @@ def numbers(
|
|
737
727
|
##
|
738
728
|
|
739
729
|
|
740
|
-
def pairs(
|
741
|
-
strategy: SearchStrategy[
|
730
|
+
def pairs[T](
|
731
|
+
strategy: SearchStrategy[T],
|
742
732
|
/,
|
743
733
|
*,
|
744
734
|
unique: MaybeSearchStrategy[bool] = False,
|
745
735
|
sorted: MaybeSearchStrategy[bool] = False, # noqa: A002
|
746
|
-
) -> SearchStrategy[tuple[
|
736
|
+
) -> SearchStrategy[tuple[T, T]]:
|
747
737
|
"""Strategy for generating pairs of elements."""
|
748
738
|
return lists_fixed_length(strategy, 2, unique=unique, sorted=sorted).map(_pairs_map)
|
749
739
|
|
750
740
|
|
751
|
-
def _pairs_map(elements: list[
|
741
|
+
def _pairs_map[T](elements: list[T], /) -> tuple[T, T]:
|
752
742
|
first, second = elements
|
753
743
|
return first, second
|
754
744
|
|
@@ -824,9 +814,9 @@ def sentinels() -> SearchStrategy[Sentinel]:
|
|
824
814
|
|
825
815
|
|
826
816
|
@composite
|
827
|
-
def sets_fixed_length(
|
828
|
-
draw: DrawFn, strategy: SearchStrategy[
|
829
|
-
) -> set[
|
817
|
+
def sets_fixed_length[T](
|
818
|
+
draw: DrawFn, strategy: SearchStrategy[T], size: MaybeSearchStrategy[int], /
|
819
|
+
) -> set[T]:
|
830
820
|
"""Strategy for generating lists of a fixed length."""
|
831
821
|
size_ = draw2(draw, size)
|
832
822
|
return draw(sets(strategy, min_size=size_, max_size=size_))
|
@@ -1177,20 +1167,20 @@ def times(
|
|
1177
1167
|
##
|
1178
1168
|
|
1179
1169
|
|
1180
|
-
def triples(
|
1181
|
-
strategy: SearchStrategy[
|
1170
|
+
def triples[T](
|
1171
|
+
strategy: SearchStrategy[T],
|
1182
1172
|
/,
|
1183
1173
|
*,
|
1184
1174
|
unique: MaybeSearchStrategy[bool] = False,
|
1185
1175
|
sorted: MaybeSearchStrategy[bool] = False, # noqa: A002
|
1186
|
-
) -> SearchStrategy[tuple[
|
1176
|
+
) -> SearchStrategy[tuple[T, T, T]]:
|
1187
1177
|
"""Strategy for generating triples of elements."""
|
1188
1178
|
return lists_fixed_length(strategy, 3, unique=unique, sorted=sorted).map(
|
1189
1179
|
_triples_map
|
1190
1180
|
)
|
1191
1181
|
|
1192
1182
|
|
1193
|
-
def _triples_map(elements: list[
|
1183
|
+
def _triples_map[T](elements: list[T], /) -> tuple[T, T, T]:
|
1194
1184
|
first, second, third = elements
|
1195
1185
|
return first, second, third
|
1196
1186
|
|