jetpytools 1.7.4__py3-none-any.whl → 2.0.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.

Potentially problematic release.


This version of jetpytools might be problematic. Click here for more details.

jetpytools/utils/funcs.py CHANGED
@@ -2,9 +2,7 @@ from __future__ import annotations
2
2
 
3
3
  from functools import update_wrapper
4
4
  from types import FunctionType
5
- from typing import Any, Callable, Sequence
6
-
7
- from ..types import F
5
+ from typing import Any, Callable, Protocol, Sequence, runtime_checkable
8
6
 
9
7
  __all__ = ["copy_func", "erase_module"]
10
8
 
@@ -14,17 +12,22 @@ def copy_func(f: Callable[..., Any]) -> FunctionType:
14
12
 
15
13
  try:
16
14
  g = FunctionType(f.__code__, f.__globals__, name=f.__name__, argdefs=f.__defaults__, closure=f.__closure__)
15
+ g.__kwdefaults__ = f.__kwdefaults__
17
16
  g = update_wrapper(g, f)
18
- g.__kwdefaults__ = f.__kwdefaults__ # type: ignore
19
- return g # type: ignore
20
- except BaseException: # for builtins
21
- return f # type: ignore
17
+ return g # type: ignore[return-value]
18
+ except BaseException:
19
+ return f # type: ignore[return-value]
20
+
21
+
22
+ @runtime_checkable
23
+ class _HasModule(Protocol):
24
+ __module__: str
22
25
 
23
26
 
24
- def erase_module(func: F, modules: Sequence[str] | None = None) -> F:
27
+ def erase_module[F: Callable[..., Any]](func: F, modules: Sequence[str] | None = None) -> F:
25
28
  """Delete the __module__ of the function."""
26
29
 
27
- if hasattr(func, "__module__") and (True if modules is None else (func.__module__ in modules)):
28
- func.__module__ = None # type: ignore
30
+ if isinstance(func, _HasModule) and (modules is None or func.__module__ in modules):
31
+ func.__module__ = ""
29
32
 
30
33
  return func
jetpytools/utils/math.py CHANGED
@@ -3,8 +3,6 @@ from __future__ import annotations
3
3
  from math import ceil, log, log10
4
4
  from typing import Sequence
5
5
 
6
- from ..types import Nb
7
-
8
6
  __all__ = [
9
7
  "clamp",
10
8
  "clamp_arr",
@@ -20,13 +18,13 @@ __all__ = [
20
18
  ]
21
19
 
22
20
 
23
- def clamp(val: Nb, min_val: Nb, max_val: Nb) -> Nb:
21
+ def clamp[Nb: (int, float)](val: Nb, min_val: Nb, max_val: Nb) -> Nb:
24
22
  """Faster max(min(value, max_val), min_val) "wrapper" """
25
23
 
26
24
  return min_val if val < min_val else max_val if val > max_val else val
27
25
 
28
26
 
29
- def clamp_arr(vals: Sequence[Nb], min_val: Nb, max_val: Nb) -> list[Nb]:
27
+ def clamp_arr[Nb: (int, float)](vals: Sequence[Nb], min_val: Nb, max_val: Nb) -> list[Nb]:
30
28
  """Map an array to clamp."""
31
29
 
32
30
  return [clamp(x, min_val, max_val) for x in vals]
@@ -163,7 +161,7 @@ def spline_coeff(
163
161
  return float(s)
164
162
 
165
163
 
166
- def ndigits(num: Nb) -> int:
164
+ def ndigits(num: float) -> int:
167
165
  if num == 0:
168
166
  return 1
169
167
 
@@ -1,57 +1,12 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  from itertools import chain, zip_longest
4
- from typing import Iterable, overload
4
+ from typing import Iterable
5
5
 
6
- from ..exceptions import CustomIndexError
7
- from ..types import T0, T
6
+ __all__ = ["interleave_arr"]
8
7
 
9
- __all__ = ["interleave_arr", "ranges_product"]
10
8
 
11
-
12
- @overload
13
- def ranges_product(range0: range | int, range1: range | int, /) -> Iterable[tuple[int, int]]: ...
14
-
15
-
16
- @overload
17
- def ranges_product(
18
- range0: range | int, range1: range | int, range2: range | int, /
19
- ) -> Iterable[tuple[int, int, int]]: ...
20
-
21
-
22
- def ranges_product(*_iterables: range | int) -> Iterable[tuple[int, ...]]:
23
- """
24
- Take two or three lengths/ranges and make a cartesian product of them.
25
-
26
- Useful for getting all coordinates of an image.
27
- For example ranges_product(1920, 1080) will give you [(0, 0), (0, 1), (0, 2), ..., (1919, 1078), (1919, 1079)].
28
- """
29
-
30
- n_iterables = len(_iterables)
31
-
32
- if n_iterables <= 1:
33
- raise CustomIndexError(f"Not enough ranges passed! ({n_iterables})", ranges_product)
34
-
35
- iterables = [range(x) if isinstance(x, int) else x for x in _iterables]
36
-
37
- if n_iterables == 2:
38
- first_it, second_it = iterables
39
-
40
- for xx in first_it:
41
- for yy in second_it:
42
- yield xx, yy
43
- elif n_iterables == 3:
44
- first_it, second_it, third_it = iterables
45
-
46
- for xx in first_it:
47
- for yy in second_it:
48
- for zz in third_it:
49
- yield xx, yy, zz
50
- else:
51
- raise CustomIndexError(f"Too many ranges passed! ({n_iterables})", ranges_product)
52
-
53
-
54
- def interleave_arr(arr0: Iterable[T], arr1: Iterable[T0], n: int = 2) -> Iterable[T | T0]:
9
+ def interleave_arr[T0, T1](arr0: Iterable[T0], arr1: Iterable[T1], n: int = 2) -> Iterable[T0 | T1]:
55
10
  """
56
11
  Interleave two arrays of variable length.
57
12
 
@@ -62,9 +17,13 @@ def interleave_arr(arr0: Iterable[T], arr1: Iterable[T0], n: int = 2) -> Iterabl
62
17
 
63
18
  :yield: Elements from either arr0 or arr01.
64
19
  """
65
- if n == 1:
66
- yield from (x for x in chain.from_iterable(zip_longest(arr0, arr1)) if x is not None)
20
+ if n <= 0:
21
+ raise ValueError("n must be a positive integer")
67
22
 
23
+ if n == 1:
24
+ for x in chain.from_iterable(zip_longest(arr0, arr1, fillvalue=None)):
25
+ if x is not None:
26
+ yield x
68
27
  return
69
28
 
70
29
  arr0_i, arr1_i = iter(arr0), iter(arr1)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: jetpytools
3
- Version: 1.7.4
3
+ Version: 2.0.1
4
4
  Summary: Collection of stuff that's useful in general python programming
5
5
  Project-URL: Source Code, https://github.com/Jaded-Encoding-Thaumaturgy/jetpytools
6
6
  Project-URL: Contact, https://discord.gg/XTpc6Fa9eB
@@ -15,8 +15,8 @@ Classifier: Operating System :: OS Independent
15
15
  Classifier: Programming Language :: Python :: 3
16
16
  Classifier: Programming Language :: Python :: 3 :: Only
17
17
  Classifier: Typing :: Typed
18
- Requires-Python: >=3.10
19
- Requires-Dist: typing-extensions>=4.12.2
18
+ Requires-Python: >=3.12
19
+ Requires-Dist: typing-extensions>=4.15.0
20
20
  Description-Content-Type: text/markdown
21
21
 
22
22
  # jetpytools
@@ -0,0 +1,33 @@
1
+ jetpytools/__init__.py,sha256=ha_pCOMqfeIbipDRrtqKOqH3NQEpX4KwN2SskpsCGb4,114
2
+ jetpytools/_metadata.py,sha256=Sh6w1MTmnsiXSW7bySj3rvnKAj6r6vq0Jf8-TqTi00Q,414
3
+ jetpytools/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ jetpytools/enums/__init__.py,sha256=TvEt3TWmnzf2TWS_Gd6llyyXAGDKxdhdJsDgSvT7xys,41
5
+ jetpytools/enums/base.py,sha256=Vuzlv84jXUCje7-yoyjucPcgkmfVkLHuuLXcmx4z1Yw,1970
6
+ jetpytools/enums/other.py,sha256=Fwf8J98cqFQbnDsOPV90RTOJ_Ltd72Y3qVbSDzOl5Eg,1346
7
+ jetpytools/exceptions/__init__.py,sha256=0rNEfnOuoSRUyKsutGzHFWQkgiFaK7diOT4VbRVKt9c,105
8
+ jetpytools/exceptions/base.py,sha256=cKvND21z0McwbhpOg9oVYyMvLVa8MDs9m1g4FUbEHvM,6949
9
+ jetpytools/exceptions/enum.py,sha256=euR6cyMetVWSfTgO5rkblhQyEgusdwhx6Rd9I5ZoFbA,293
10
+ jetpytools/exceptions/file.py,sha256=7Eh4aPo4r1W-ppnf6XLwWaStOSjIxw9JfzOCa4W7m8E,1105
11
+ jetpytools/exceptions/generic.py,sha256=dUMt70XW2QwQtyfwegPO_bfF4QNQOEMtqY9FfAMapFA,1504
12
+ jetpytools/exceptions/module.py,sha256=iRKvbxa59MYDavIQIzPR-NjqjhZbBTLRvzAONMXs3Aw,1228
13
+ jetpytools/functions/__init__.py,sha256=jCw3-aaOGxIzi6iyFInWPOxOFbzZg8IZhoSuGYaNgLA,67
14
+ jetpytools/functions/funcs.py,sha256=_6zzloyVPE4GqRqqAsxiG4l49-dfVTEx7HsTP44p1VE,5306
15
+ jetpytools/functions/normalize.py,sha256=zrhOIBjO1558-BxYjXQuZxuP_VjHmAIHYDVefiBwN0M,8532
16
+ jetpytools/functions/other.py,sha256=P_NdrtFxR_Sosn9QblU-Ea4mKEyWY7AegQzmiQPSVLk,407
17
+ jetpytools/types/__init__.py,sha256=oP1cm6LtRpjPXQ0M4JnKH4RkzrBxBPos_xLHaITrgSs,154
18
+ jetpytools/types/builtins.py,sha256=dGevzNAC6szmQpcvH6jiYMk_h6wHwmcYdqeD1AAty9k,925
19
+ jetpytools/types/check.py,sha256=ktQOykmryUkDa2j-zcL6uEWF8QlxJ4GW8YKdbqMHGcc,959
20
+ jetpytools/types/file.py,sha256=6hV332qbBtvg3p3g6tNHiSnZGp4DhtcTZm-Vap7M72k,6400
21
+ jetpytools/types/funcs.py,sha256=arlykyVyosdjBhUTrJDfAoGBdkI5zhoJc0yINMQEonw,2804
22
+ jetpytools/types/generic.py,sha256=LlYiD54GPi5ghjdw4wJmulrZiqv5IUnfPfyr-fk-RlA,1138
23
+ jetpytools/types/supports.py,sha256=uZ2N7XxAa5H3QcOKStCH8fp2x6EXvoKwLQZue5xTLFY,3400
24
+ jetpytools/types/utils.py,sha256=GoRx3fjHRbdQ27L4jkUb_oUXAtupGUI2FHHWp8ccEWw,29599
25
+ jetpytools/utils/__init__.py,sha256=_rJ-mY5PsGjBfy8Fihx_FYJfAIGSrYAYzI6Td9oFh9A,83
26
+ jetpytools/utils/file.py,sha256=3fJxAHjIN5zdyzO0guc3jDspcs5HPG4t4cwB_ZrAhh4,10622
27
+ jetpytools/utils/funcs.py,sha256=2jOOIUQpifQ_kTuVUSrCAi8hvCmmvieBpMTfF8XuM24,979
28
+ jetpytools/utils/math.py,sha256=ZqsAyVNBT4LD-zqP7QxEkGwWdVfrR7YAkdv87NQTMV0,3460
29
+ jetpytools/utils/ranges.py,sha256=RAknSZkTAYxAXdFn_CKY8xGASu7xS7Gu039DX89ugDc,1293
30
+ jetpytools-2.0.1.dist-info/METADATA,sha256=c0AIK2JpabO43aUHc_3G-4wYSF4X19hcJw2goRGb-Oc,1198
31
+ jetpytools-2.0.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
32
+ jetpytools-2.0.1.dist-info/licenses/LICENSE,sha256=l0PN-qDtXcgOB5aXP_nSUsvCK5V3o9pQCGsTzyZhKL0,1071
33
+ jetpytools-2.0.1.dist-info/RECORD,,
@@ -1,33 +0,0 @@
1
- jetpytools/__init__.py,sha256=ha_pCOMqfeIbipDRrtqKOqH3NQEpX4KwN2SskpsCGb4,114
2
- jetpytools/_metadata.py,sha256=Ctf45XxZkSp6UiAUvlc0xW27P8V4tEMiFFSZtpGLKxA,414
3
- jetpytools/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
- jetpytools/enums/__init__.py,sha256=TvEt3TWmnzf2TWS_Gd6llyyXAGDKxdhdJsDgSvT7xys,41
5
- jetpytools/enums/base.py,sha256=s5A9iQS22JdaZMM6jEXI31m0ZjtBx7GLQ-E0xBr90Zc,2032
6
- jetpytools/enums/other.py,sha256=9GGRS4P-P589C1HqNpDDBhLdphID1trwCJi7pbXT0iM,1317
7
- jetpytools/exceptions/__init__.py,sha256=0rNEfnOuoSRUyKsutGzHFWQkgiFaK7diOT4VbRVKt9c,105
8
- jetpytools/exceptions/base.py,sha256=4DNDYlH_196sZH9_B-mvs4pRxr2kcO3JSwDBmAaRT8o,7645
9
- jetpytools/exceptions/enum.py,sha256=euR6cyMetVWSfTgO5rkblhQyEgusdwhx6Rd9I5ZoFbA,293
10
- jetpytools/exceptions/file.py,sha256=7Eh4aPo4r1W-ppnf6XLwWaStOSjIxw9JfzOCa4W7m8E,1105
11
- jetpytools/exceptions/generic.py,sha256=91U6RoiAoejFOU2qjaJsmej8FhC0XXQuZ535XTi1qGA,1504
12
- jetpytools/exceptions/module.py,sha256=iRKvbxa59MYDavIQIzPR-NjqjhZbBTLRvzAONMXs3Aw,1228
13
- jetpytools/functions/__init__.py,sha256=jCw3-aaOGxIzi6iyFInWPOxOFbzZg8IZhoSuGYaNgLA,67
14
- jetpytools/functions/funcs.py,sha256=lcdWaJtslhXZNfNu_y-Badgz2uy0bVaoA3D_lLo_GNI,5286
15
- jetpytools/functions/normalize.py,sha256=czliT8iyYPdiJG3C7wHppFrOxeVP5OOWZGdRPHFvEi8,8594
16
- jetpytools/functions/other.py,sha256=P_NdrtFxR_Sosn9QblU-Ea4mKEyWY7AegQzmiQPSVLk,407
17
- jetpytools/types/__init__.py,sha256=oP1cm6LtRpjPXQ0M4JnKH4RkzrBxBPos_xLHaITrgSs,154
18
- jetpytools/types/builtins.py,sha256=4uAutpHlkcKM3K_6BbWomqR2QgWNt6294FHE3Ck_ZIA,2067
19
- jetpytools/types/check.py,sha256=ktQOykmryUkDa2j-zcL6uEWF8QlxJ4GW8YKdbqMHGcc,959
20
- jetpytools/types/file.py,sha256=LbOwMAwDALWxAZZ2i7ZNexoN3GHWD-uUoIhVvUy95Vo,6539
21
- jetpytools/types/funcs.py,sha256=U5tBmTtLS5CLp3ZtOiA5101PQiCWQOBsmf0bj1pRwgY,2778
22
- jetpytools/types/generic.py,sha256=RRg2U7wxaM4Uzwc6QvsO99euCF3sqr8Kh34XKtVbgT8,1136
23
- jetpytools/types/supports.py,sha256=woMTv62HpcRiC5TG18U8NU5v2Q6iqcrHzQgXl7QYEws,3516
24
- jetpytools/types/utils.py,sha256=2E7eNZjwlkQIL-9KC7xj7nMULTHoivrUI22rdzPRw88,23651
25
- jetpytools/utils/__init__.py,sha256=_rJ-mY5PsGjBfy8Fihx_FYJfAIGSrYAYzI6Td9oFh9A,83
26
- jetpytools/utils/file.py,sha256=3fJxAHjIN5zdyzO0guc3jDspcs5HPG4t4cwB_ZrAhh4,10622
27
- jetpytools/utils/funcs.py,sha256=2qhFyLD0OLvenjzOu2wu1ZWoZGzQ8aPmvbkAI1i9Gvk,914
28
- jetpytools/utils/math.py,sha256=I56OeHDDJl3X8EFXMWVEiXGAD16AKcn8KVnFuP5fFes,3445
29
- jetpytools/utils/ranges.py,sha256=glxypgmuzauV6KCSNujNHOdWkNEUNylOUAPS618jnIg,2559
30
- jetpytools-1.7.4.dist-info/METADATA,sha256=DP5E8ygPnwnPuriFpgxkrCLDQUqjzU93xiU-m1XnmD0,1198
31
- jetpytools-1.7.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
32
- jetpytools-1.7.4.dist-info/licenses/LICENSE,sha256=l0PN-qDtXcgOB5aXP_nSUsvCK5V3o9pQCGsTzyZhKL0,1071
33
- jetpytools-1.7.4.dist-info/RECORD,,