dycw-utilities 0.134.0__py3-none-any.whl → 0.134.2__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dycw-utilities
3
- Version: 0.134.0
3
+ Version: 0.134.2
4
4
  Author-email: Derek Wan <d.wan@icloud.com>
5
5
  License-File: LICENSE
6
6
  Requires-Python: >=3.12
@@ -1,4 +1,4 @@
1
- utilities/__init__.py,sha256=6Kft8t6oHMNZG-gaM4ZQ07SvvDvKryeqHULU_jPaWnE,60
1
+ utilities/__init__.py,sha256=3l_xarfe4CxRZA0THTNWrLa3nhX96z__Dw-8p3WRIqA,60
2
2
  utilities/aiolimiter.py,sha256=mD0wEiqMgwpty4XTbawFpnkkmJS6R4JRsVXFUaoitSU,628
3
3
  utilities/altair.py,sha256=HeZBVUocjkrTNwwKrClppsIqgNFF-ykv05HfZSoHYno,9104
4
4
  utilities/arq.py,sha256=S-sfBfY-E1ErRKf4sSXt2YyCjKvu-pBlOECDfjBebRA,6399
@@ -19,7 +19,7 @@ utilities/eventkit.py,sha256=cV76NIHKDPyrhnZRuhjCXse5CQqgRGXZ7p7Gon4Mu2g,12646
19
19
  utilities/fastapi.py,sha256=E8T2J1-N_RbpkN4czthU6NPIxAZDzxy-k_WGJaxeJ48,2671
20
20
  utilities/fpdf2.py,sha256=PmPj8ugr_SlxFEpw-9OsI8--mteLQ4MaXv_Cbmf7XXs,1852
21
21
  utilities/functions.py,sha256=Teqm7ylOqEcBLHWhRwjKqouUfc6nv_6qO6fILpnOPyA,27937
22
- utilities/functools.py,sha256=mQv5yPMAy2CPVPnbxvRHhnDX3DnnyF1Mz5DIFWzWcro,1512
22
+ utilities/functools.py,sha256=I00ru2gQPakZw2SHVeKIKXfTv741655s6HI0lUoE0D4,1552
23
23
  utilities/getpass.py,sha256=DfN5UgMAtFCqS3dSfFHUfqIMZX2shXvwphOz_6J6f6A,103
24
24
  utilities/git.py,sha256=oi7-_l5e9haSANSCvQw25ufYGoNahuUPHAZ6114s3JQ,1191
25
25
  utilities/hashlib.py,sha256=SVTgtguur0P4elppvzOBbLEjVM3Pea0eWB61yg2ilxo,309
@@ -53,6 +53,7 @@ utilities/polars_ols.py,sha256=Uc9V5kvlWZ5cU93lKZ-cfAKdVFFw81tqwLW9PxtUvMs,5618
53
53
  utilities/pottery.py,sha256=RN3XwOEsVAPXvEfsRPmn3ZSKgTzK_c182PNrtksq-bg,3429
54
54
  utilities/pqdm.py,sha256=BTsYPtbKQWwX-iXF4qCkfPG7DPxIB54J989n83bXrIo,3092
55
55
  utilities/psutil.py,sha256=0j4YxtVb8VjaaKKiHg6UEK95SUPkEcENgPtLgPJsNv0,3760
56
+ utilities/pudb.py,sha256=Dte7P9J0VWrWTNYvwxZX6kgaEtdTt5ZnnmOAUTjltqU,1771
56
57
  utilities/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
57
58
  utilities/pydantic.py,sha256=CmxCi4sukeHM3JGjJ1Rbp8UAvcx4MZapLg10mFYJ-nk,1771
58
59
  utilities/pyinstrument.py,sha256=_Rfq6Gg4NKV2NF0dRYOpK2IRyyePxI7-3UmHIQLYrlQ,852
@@ -89,7 +90,7 @@ utilities/warnings.py,sha256=un1LvHv70PU-LLv8RxPVmugTzDJkkGXRMZTE2-fTQHw,1771
89
90
  utilities/whenever.py,sha256=A-yoOqBqrcVD1yDINDsTFDw7dq9-zgUGn_f8CxVUQJs,23332
90
91
  utilities/zipfile.py,sha256=24lQc9ATcJxHXBPc_tBDiJk48pWyRrlxO2fIsFxU0A8,699
91
92
  utilities/zoneinfo.py,sha256=oEH-nL3t4h9uawyZqWDtNtDAl6M-CLpLYGI_nI6DulM,1971
92
- dycw_utilities-0.134.0.dist-info/METADATA,sha256=ge1UR3zk8DRZIcXfN3RY6DR9oh5TJ-nT-A2YWjlPz_4,1584
93
- dycw_utilities-0.134.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
94
- dycw_utilities-0.134.0.dist-info/licenses/LICENSE,sha256=gppZp16M6nSVpBbUBrNL6JuYfvKwZiKgV7XoKKsHzqo,1066
95
- dycw_utilities-0.134.0.dist-info/RECORD,,
93
+ dycw_utilities-0.134.2.dist-info/METADATA,sha256=jP7BRWqiFgPVdbALoM6g4cmSKGD85iB5_kNWuVV2tms,1584
94
+ dycw_utilities-0.134.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
95
+ dycw_utilities-0.134.2.dist-info/licenses/LICENSE,sha256=gppZp16M6nSVpBbUBrNL6JuYfvKwZiKgV7XoKKsHzqo,1066
96
+ dycw_utilities-0.134.2.dist-info/RECORD,,
utilities/__init__.py CHANGED
@@ -1,3 +1,3 @@
1
1
  from __future__ import annotations
2
2
 
3
- __version__ = "0.134.0"
3
+ __version__ = "0.134.2"
utilities/functools.py CHANGED
@@ -18,16 +18,19 @@ def cache[F: Callable](func: F, /) -> F:
18
18
  ##
19
19
 
20
20
 
21
+ _MAX_SIZE = 128
22
+
23
+
21
24
  @overload
22
25
  def lru_cache[F: Callable](
23
- func: F, /, *, max_size: int = ..., typed: bool = ...
26
+ func: F, /, *, max_size: int = _MAX_SIZE, typed: bool = False
24
27
  ) -> F: ...
25
28
  @overload
26
29
  def lru_cache[F: Callable](
27
- func: None = None, /, *, max_size: int = ..., typed: bool = ...
30
+ func: None = None, /, *, max_size: int = _MAX_SIZE, typed: bool = False
28
31
  ) -> Callable[[F], F]: ...
29
32
  def lru_cache[F: Callable](
30
- func: F | None = None, /, *, max_size: int = 128, typed: bool = False
33
+ func: F | None = None, /, *, max_size: int = _MAX_SIZE, typed: bool = False
31
34
  ) -> F | Callable[[F], F]:
32
35
  """Typed version of `lru_cache`."""
33
36
  if func is None:
utilities/pudb.py ADDED
@@ -0,0 +1,62 @@
1
+ from __future__ import annotations
2
+
3
+ from asyncio import iscoroutinefunction
4
+ from functools import partial, wraps
5
+ from typing import TYPE_CHECKING, Any, NoReturn, cast, overload
6
+
7
+ from utilities.os import GetEnvVarError, get_env_var
8
+
9
+ if TYPE_CHECKING:
10
+ from collections.abc import Callable
11
+
12
+
13
+ _ENV_VAR = "DEBUG"
14
+
15
+
16
+ @overload
17
+ def call_pudb[F: Callable](func: F, /, *, env_var: str = _ENV_VAR) -> F: ...
18
+ @overload
19
+ def call_pudb[F: Callable](
20
+ func: None = None, /, *, env_var: str = _ENV_VAR
21
+ ) -> Callable[[F], F]: ...
22
+ def call_pudb[F: Callable](
23
+ func: F | None = None, /, *, env_var: str = _ENV_VAR
24
+ ) -> F | Callable[[F], F]:
25
+ """Call `pudb` upon failure, if the required environment variable is set."""
26
+ if func is None:
27
+ result = partial(call_pudb, env_var=env_var)
28
+ return cast("Callable[[F], F]", result)
29
+
30
+ if not iscoroutinefunction(func):
31
+
32
+ @wraps(func)
33
+ def wrapped_sync(*args: Any, **kwargs: Any) -> Any:
34
+ try:
35
+ return func(*args, **kwargs)
36
+ except Exception as error: # noqa: BLE001
37
+ _call_pudb(error, env_var=env_var)
38
+
39
+ return cast("F", wrapped_sync)
40
+
41
+ @wraps(func)
42
+ async def wrapped_async(*args: Any, **kwargs: Any) -> Any:
43
+ try:
44
+ return await func(*args, **kwargs)
45
+ except Exception as error: # noqa: BLE001
46
+ _call_pudb(error, env_var=env_var)
47
+
48
+ return cast("F", wrapped_async)
49
+
50
+
51
+ def _call_pudb(error: Exception, /, *, env_var: str = _ENV_VAR) -> NoReturn:
52
+ try:
53
+ _ = get_env_var(env_var)
54
+ except GetEnvVarError:
55
+ raise error from None
56
+ from pudb import post_mortem # pragma: no cover
57
+
58
+ post_mortem() # pragma: no cover
59
+ raise error # pragma: no cover
60
+
61
+
62
+ __all__ = ["call_pudb"]