jetpytools 1.7.1__py3-none-any.whl → 1.7.3__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/_metadata.py CHANGED
@@ -1,6 +1,6 @@
1
1
  """Collection of stuff that's useful in general python programming"""
2
2
 
3
- __version__ = "1.7.1"
3
+ __version__ = "1.7.3"
4
4
 
5
5
  __author_name__, __author_email__ = "Jaded Encoding Thaumaturgy", "jaded.encoding.thaumaturgy@gmail.com"
6
6
  __maintainer_name__, __maintainer_email__ = __author_name__, __author_email__
jetpytools/enums/base.py CHANGED
@@ -6,7 +6,7 @@ from typing import Any
6
6
  from typing_extensions import Self
7
7
 
8
8
  from ..exceptions import CustomValueError, NotFoundEnumValue
9
- from ..types import FuncExceptT
9
+ from ..types import FuncExcept
10
10
 
11
11
  __all__ = ["CustomEnum", "CustomIntEnum", "CustomStrEnum"]
12
12
 
@@ -19,7 +19,7 @@ class CustomEnum(Enum):
19
19
  return cls.from_param(value)
20
20
 
21
21
  @classmethod
22
- def from_param(cls, value: Any, func_except: FuncExceptT | None = None) -> Self | None:
22
+ def from_param(cls, value: Any, func_except: FuncExcept | None = None) -> Self | None:
23
23
  """
24
24
  Return the enum value from a parameter.
25
25
 
@@ -8,7 +8,7 @@ from typing import TYPE_CHECKING, Any, Generic, TypeVar
8
8
 
9
9
  from typing_extensions import Self
10
10
 
11
- from ..types import MISSING, FuncExceptT, MissingT, SupportsString
11
+ from ..types import MISSING, FuncExcept, MissingT, SupportsString
12
12
 
13
13
  __all__ = [
14
14
  "CustomError",
@@ -80,7 +80,7 @@ class CustomError(ExceptionError, metaclass=CustomErrorMeta):
80
80
  """Custom base exception class."""
81
81
 
82
82
  def __init__(
83
- self, message: SupportsString | None = None, func: FuncExceptT | None = None, reason: Any = None, **kwargs: Any
83
+ self, message: SupportsString | None = None, func: FuncExcept | None = None, reason: Any = None, **kwargs: Any
84
84
  ) -> None:
85
85
  """
86
86
  Instantiate a new exception with pretty printing and more.
@@ -107,8 +107,8 @@ class CustomError(ExceptionError, metaclass=CustomErrorMeta):
107
107
  def __call__(
108
108
  self,
109
109
  message: SupportsString | None | MissingT = MISSING,
110
- func: FuncExceptT | None | MissingT = MISSING,
111
- reason: SupportsString | FuncExceptT | None | MissingT = MISSING,
110
+ func: FuncExcept | None | MissingT = MISSING,
111
+ reason: SupportsString | FuncExcept | None | MissingT = MISSING,
112
112
  **kwargs: Any,
113
113
  ) -> Self:
114
114
  """
@@ -2,7 +2,7 @@ from __future__ import annotations
2
2
 
3
3
  from typing import Any, Iterable
4
4
 
5
- from ..types import FuncExceptT, SupportsString, T
5
+ from ..types import FuncExcept, SupportsString, T
6
6
  from .base import CustomValueError
7
7
 
8
8
  __all__ = ["MismatchError", "MismatchRefError"]
@@ -21,7 +21,7 @@ class MismatchError(CustomValueError):
21
21
 
22
22
  def __init__(
23
23
  self,
24
- func: FuncExceptT,
24
+ func: FuncExcept,
25
25
  items: Iterable[Any],
26
26
  message: SupportsString = "All items must be equal!",
27
27
  reason: Any = "{reduced_items}",
@@ -30,18 +30,18 @@ class MismatchError(CustomValueError):
30
30
  super().__init__(message, func, reason, **kwargs, reduced_items=iter(self._reduce(items)))
31
31
 
32
32
  @classmethod
33
- def check(cls, func: FuncExceptT, /, *items: Any, **kwargs: Any) -> None:
33
+ def check(cls, func: FuncExcept, /, *items: Any, **kwargs: Any) -> None:
34
34
  if len(cls._reduce(items)) != 1:
35
35
  raise cls(func, items, **kwargs)
36
36
 
37
37
 
38
38
  class MismatchRefError(MismatchError):
39
39
  def __init__(
40
- self, func: FuncExceptT, base: T, ref: T, message: SupportsString = "All items must be equal!", **kwargs: Any
40
+ self, func: FuncExcept, base: T, ref: T, message: SupportsString = "All items must be equal!", **kwargs: Any
41
41
  ) -> None:
42
42
  super().__init__(func, [base, ref], message, **kwargs)
43
43
 
44
44
  @classmethod
45
- def check(cls, func: FuncExceptT, /, *items: Any, **kwargs: Any) -> None:
45
+ def check(cls, func: FuncExcept, /, *items: Any, **kwargs: Any) -> None:
46
46
  if len(cls._reduce(items)) != 1:
47
47
  raise cls(func, *items, **kwargs)
@@ -2,7 +2,7 @@ from __future__ import annotations
2
2
 
3
3
  from typing import Any
4
4
 
5
- from ..types import FuncExceptT, SupportsString
5
+ from ..types import FuncExcept, SupportsString
6
6
  from .base import CustomError
7
7
 
8
8
  __all__ = ["CustomImportError", "DependencyNotFoundError"]
@@ -13,7 +13,7 @@ class CustomImportError(CustomError, ImportError):
13
13
 
14
14
  def __init__(
15
15
  self,
16
- func: FuncExceptT,
16
+ func: FuncExcept,
17
17
  package: str | ImportError,
18
18
  message: SupportsString = "Import failed for package '{package}'!",
19
19
  **kwargs: Any,
@@ -32,7 +32,7 @@ class DependencyNotFoundError(CustomImportError):
32
32
 
33
33
  def __init__(
34
34
  self,
35
- func: FuncExceptT,
35
+ func: FuncExcept,
36
36
  package: str | ImportError,
37
37
  message: SupportsString = "Missing dependency '{package}'!",
38
38
  **kwargs: Any,
@@ -6,23 +6,23 @@ from typing import Any, Callable, Literal, TypeAlias, Union
6
6
  from .builtins import F, SingleOrArr, SingleOrArrOpt
7
7
  from .supports import SupportsString
8
8
 
9
- __all__ = ["MISSING", "DataType", "FuncExceptT", "MissingT", "PassthroughC", "StrArr", "StrArrOpt"]
9
+ __all__ = ["MISSING", "DataType", "FuncExcept", "FuncExceptT", "MissingT", "PassthroughC", "StrArr", "StrArrOpt"]
10
10
 
11
11
 
12
- class MissingTBase(Enum):
13
- MissingT = auto()
12
+ class _MissingType(Enum):
13
+ MISSING = auto()
14
14
 
15
15
 
16
- MissingT: TypeAlias = Literal[MissingTBase.MissingT]
17
- MISSING = MissingTBase.MissingT
16
+ MissingT: TypeAlias = Literal[_MissingType.MISSING]
17
+ MISSING = _MissingType.MISSING
18
18
 
19
19
  DataType = Union[str, bytes, bytearray, SupportsString]
20
20
 
21
- FuncExceptT = str | Callable[..., Any] | tuple[Callable[..., Any] | str, str]
21
+ FuncExcept = str | Callable[..., Any] | tuple[Callable[..., Any] | str, str]
22
22
  """
23
23
  This type is used in specific functions that can throw an exception.
24
24
  ```
25
- def can_throw(..., *, func: FuncExceptT) -> None:
25
+ def can_throw(..., *, func: FuncExcept) -> None:
26
26
  ...
27
27
  if some_error:
28
28
  raise CustomValueError('Some error occurred!!', func)
@@ -35,6 +35,7 @@ If an error occurs, this will print a clear error ->\n
35
35
  ``ValueError: (some_func) Some error occurred!!``
36
36
  """
37
37
 
38
+ FuncExceptT = FuncExcept
38
39
 
39
40
  StrArr = SingleOrArr[SupportsString]
40
41
  StrArrOpt = SingleOrArrOpt[SupportsString]
jetpytools/types/utils.py CHANGED
@@ -23,7 +23,7 @@ from typing import (
23
23
  overload,
24
24
  )
25
25
 
26
- from typing_extensions import Self, deprecated
26
+ from typing_extensions import Self, TypeVar, deprecated
27
27
 
28
28
  from .builtins import F0, F1, P0, P1, R0, R1, T0, KwargsT, P, R, R0_co, R1_co, R_co, T, T0_co, T1_co, T_co
29
29
 
@@ -43,9 +43,9 @@ __all__ = [
43
43
  # ruff: noqa: N801
44
44
 
45
45
 
46
- class copy_signature(Generic[F0]):
46
+ def copy_signature(target: F0, /) -> Callable[[Callable[..., Any]], F0]:
47
47
  """
48
- Type util to copy the signature of one function to another function.
48
+ Utility function to copy the signature of one function to another one.
49
49
 
50
50
  Especially useful for passthrough functions.
51
51
 
@@ -71,12 +71,11 @@ class copy_signature(Generic[F0]):
71
71
  # another thing
72
72
  """
73
73
 
74
- def __init__(self, target: F0) -> None:
75
- """Copy the signature of ``target``."""
76
-
77
- def __call__(self, wrapped: Callable[..., Any]) -> F0:
74
+ def decorator(wrapped: Callable[..., Any]) -> F0:
78
75
  return cast(F0, wrapped)
79
76
 
77
+ return decorator
78
+
80
79
 
81
80
  class injected_self_func(Protocol[T_co, P, R_co]):
82
81
  @overload
@@ -517,7 +516,10 @@ class classproperty(classproperty_base[T, R_co]):
517
516
  del cache[name]
518
517
 
519
518
 
520
- class cachedproperty(property, Generic[R_co]):
519
+ _T_cc = TypeVar("_T_cc", default=Any)
520
+
521
+
522
+ class cachedproperty(property, Generic[R_co, _T_cc]):
521
523
  """
522
524
  Wrapper for a one-time get property, that will be cached.
523
525
 
@@ -539,16 +541,16 @@ class cachedproperty(property, Generic[R_co]):
539
541
  def __init__(
540
542
  self,
541
543
  fget: Callable[[Any], R_co],
542
- fset: Callable[[Any, Any], None] | None = None,
544
+ fset: Callable[[Any, _T_cc], None] | None = None,
543
545
  fdel: Callable[[Any], None] | None = None,
544
546
  doc: str | None = None,
545
547
  ) -> None: ...
546
548
 
547
- def getter(self, fget: Callable[..., R_co]) -> cachedproperty[R_co]: ...
549
+ def getter(self, fget: Callable[..., R_co]) -> cachedproperty[R_co, _T_cc]: ...
548
550
 
549
- def setter(self, fset: Callable[[Any, Any], None]) -> cachedproperty[R_co]: ...
551
+ def setter(self, fset: Callable[[Any, _T_cc], None]) -> cachedproperty[R_co, _T_cc]: ...
550
552
 
551
- def deleter(self, fdel: Callable[..., None]) -> cachedproperty[R_co]: ...
553
+ def deleter(self, fdel: Callable[..., None]) -> cachedproperty[R_co, _T_cc]: ...
552
554
 
553
555
  if sys.version_info < (3, 13):
554
556
 
@@ -573,7 +575,7 @@ class cachedproperty(property, Generic[R_co]):
573
575
  cache[self.__name__] = value
574
576
  return value
575
577
 
576
- def __set__(self, instance: Any, value: Any) -> None:
578
+ def __set__(self, instance: Any, value: _T_cc) -> None:
577
579
  if self.__name__ in (cache := instance.__dict__.setdefault(self.cache_key, {})):
578
580
  del cache[self.__name__]
579
581
 
@@ -605,6 +607,17 @@ class cachedproperty(property, Generic[R_co]):
605
607
  with suppress(KeyError):
606
608
  del cache[name]
607
609
 
610
+ @classmethod
611
+ def update_cache(cls, obj: object, name: str, value: Any) -> None:
612
+ """
613
+ Update cached property of an object instance.
614
+
615
+ :param obj: The object whose cache should be updated.
616
+ :param names: Property name to update.
617
+ :param value: The value to assign.
618
+ """
619
+ obj.__dict__.setdefault(cls.cache_key, {})[name] = value
620
+
608
621
 
609
622
  class KwargsNotNone(KwargsT):
610
623
  """Remove all None objects from this kwargs dict."""
jetpytools/utils/file.py CHANGED
@@ -11,7 +11,7 @@ from ..exceptions import FileIsADirectoryError, FileNotExistsError, FilePermissi
11
11
  from ..types import (
12
12
  FileOpener,
13
13
  FilePathType,
14
- FuncExceptT,
14
+ FuncExcept,
15
15
  OpenBinaryMode,
16
16
  OpenBinaryModeReading,
17
17
  OpenBinaryModeUpdating,
@@ -48,7 +48,8 @@ def get_script_path() -> SPath:
48
48
  import __main__
49
49
 
50
50
  try:
51
- return SPath(__main__.__file__)
51
+ path = SPath(__main__.__file__)
52
+ return path if path.exists() else SPath.cwd()
52
53
  except AttributeError:
53
54
  return SPath.cwd()
54
55
 
@@ -73,7 +74,7 @@ def get_user_data_dir() -> Path:
73
74
 
74
75
 
75
76
  def check_perms(
76
- file: FilePathType, mode: OpenTextMode | OpenBinaryMode, strict: bool = False, *, func: FuncExceptT | None = None
77
+ file: FilePathType, mode: OpenTextMode | OpenBinaryMode, strict: bool = False, *, func: FuncExcept | None = None
77
78
  ) -> bool:
78
79
  """
79
80
  Confirm whether the user has write/read access to a file.
@@ -140,7 +141,7 @@ def open_file(
140
141
  errors: str | None = ...,
141
142
  newline: str | None = ...,
142
143
  *,
143
- func: FuncExceptT | None = None,
144
+ func: FuncExcept | None = None,
144
145
  ) -> TextIOWrapper: ...
145
146
 
146
147
 
@@ -151,7 +152,7 @@ def open_file(
151
152
  buffering: Literal[0],
152
153
  encoding: None = None,
153
154
  *,
154
- func: FuncExceptT | None = None,
155
+ func: FuncExcept | None = None,
155
156
  ) -> FileIO: ...
156
157
 
157
158
 
@@ -162,7 +163,7 @@ def open_file(
162
163
  buffering: Literal[-1, 1] = ...,
163
164
  encoding: None = None,
164
165
  *,
165
- func: FuncExceptT | None = None,
166
+ func: FuncExcept | None = None,
166
167
  ) -> BufferedRandom: ...
167
168
 
168
169
 
@@ -173,7 +174,7 @@ def open_file(
173
174
  buffering: Literal[-1, 1] = ...,
174
175
  encoding: None = None,
175
176
  *,
176
- func: FuncExceptT | None = None,
177
+ func: FuncExcept | None = None,
177
178
  ) -> BufferedWriter: ...
178
179
 
179
180
 
@@ -184,7 +185,7 @@ def open_file(
184
185
  buffering: Literal[-1, 1] = ...,
185
186
  encoding: None = None,
186
187
  *,
187
- func: FuncExceptT | None = None,
188
+ func: FuncExcept | None = None,
188
189
  ) -> BufferedReader: ...
189
190
 
190
191
 
@@ -195,7 +196,7 @@ def open_file(
195
196
  buffering: int = ...,
196
197
  encoding: None = None,
197
198
  *,
198
- func: FuncExceptT | None = None,
199
+ func: FuncExcept | None = None,
199
200
  ) -> BinaryIO: ...
200
201
 
201
202
 
@@ -210,11 +211,11 @@ def open_file(
210
211
  closefd: bool = ...,
211
212
  opener: FileOpener | None = ...,
212
213
  *,
213
- func: FuncExceptT | None = None,
214
+ func: FuncExcept | None = None,
214
215
  ) -> IO[Any]: ...
215
216
 
216
217
 
217
- def open_file(file: FilePathType, mode: Any = "r+", *args: Any, func: FuncExceptT | None = None, **kwargs: Any) -> Any:
218
+ def open_file(file: FilePathType, mode: Any = "r+", *args: Any, func: FuncExcept | None = None, **kwargs: Any) -> Any:
218
219
  """
219
220
  Open file and return a stream. Raise OSError upon failure.
220
221
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: jetpytools
3
- Version: 1.7.1
3
+ Version: 1.7.3
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
@@ -1,15 +1,15 @@
1
1
  jetpytools/__init__.py,sha256=ha_pCOMqfeIbipDRrtqKOqH3NQEpX4KwN2SskpsCGb4,114
2
- jetpytools/_metadata.py,sha256=lqi2SmD1Kr0aXukbAQaNUyoWqdq00iRpW-gpGQ3gJjw,414
2
+ jetpytools/_metadata.py,sha256=Kl3NQU3X_aFmV1c2YV8ZagO9qzZGKt0xmw4wUK8bc5Q,414
3
3
  jetpytools/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
4
  jetpytools/enums/__init__.py,sha256=TvEt3TWmnzf2TWS_Gd6llyyXAGDKxdhdJsDgSvT7xys,41
5
- jetpytools/enums/base.py,sha256=L5dk6UAsQ3V6GVj0vulKaiJsholnh0Ftyh1FZFM9zwI,2034
5
+ jetpytools/enums/base.py,sha256=s5A9iQS22JdaZMM6jEXI31m0ZjtBx7GLQ-E0xBr90Zc,2032
6
6
  jetpytools/enums/other.py,sha256=9GGRS4P-P589C1HqNpDDBhLdphID1trwCJi7pbXT0iM,1317
7
7
  jetpytools/exceptions/__init__.py,sha256=0rNEfnOuoSRUyKsutGzHFWQkgiFaK7diOT4VbRVKt9c,105
8
- jetpytools/exceptions/base.py,sha256=cCVT-v-mJoWzLvOxB5SG5dkeGAM_allXAuRgjfI9H6E,7649
8
+ jetpytools/exceptions/base.py,sha256=4DNDYlH_196sZH9_B-mvs4pRxr2kcO3JSwDBmAaRT8o,7645
9
9
  jetpytools/exceptions/enum.py,sha256=euR6cyMetVWSfTgO5rkblhQyEgusdwhx6Rd9I5ZoFbA,293
10
10
  jetpytools/exceptions/file.py,sha256=7Eh4aPo4r1W-ppnf6XLwWaStOSjIxw9JfzOCa4W7m8E,1105
11
- jetpytools/exceptions/generic.py,sha256=5LYQHdSLM2wu5fv40PTrjkW9v0iq8R-QlQzhVsiLLpE,1509
12
- jetpytools/exceptions/module.py,sha256=hjkpvTPZALRvo1Q5y7D1wEAsssjyRZSZSf98gks3lKw,1231
11
+ jetpytools/exceptions/generic.py,sha256=91U6RoiAoejFOU2qjaJsmej8FhC0XXQuZ535XTi1qGA,1504
12
+ jetpytools/exceptions/module.py,sha256=iRKvbxa59MYDavIQIzPR-NjqjhZbBTLRvzAONMXs3Aw,1228
13
13
  jetpytools/functions/__init__.py,sha256=jCw3-aaOGxIzi6iyFInWPOxOFbzZg8IZhoSuGYaNgLA,67
14
14
  jetpytools/functions/funcs.py,sha256=lcdWaJtslhXZNfNu_y-Badgz2uy0bVaoA3D_lLo_GNI,5286
15
15
  jetpytools/functions/normalize.py,sha256=czliT8iyYPdiJG3C7wHppFrOxeVP5OOWZGdRPHFvEi8,8594
@@ -19,15 +19,15 @@ jetpytools/types/builtins.py,sha256=4uAutpHlkcKM3K_6BbWomqR2QgWNt6294FHE3Ck_ZIA,
19
19
  jetpytools/types/check.py,sha256=ktQOykmryUkDa2j-zcL6uEWF8QlxJ4GW8YKdbqMHGcc,959
20
20
  jetpytools/types/file.py,sha256=LbOwMAwDALWxAZZ2i7ZNexoN3GHWD-uUoIhVvUy95Vo,6539
21
21
  jetpytools/types/funcs.py,sha256=U5tBmTtLS5CLp3ZtOiA5101PQiCWQOBsmf0bj1pRwgY,2778
22
- jetpytools/types/generic.py,sha256=SFnUqDAVehKZ36HmLrs9PN4Ze0BLcabPjwC7hJsGp4w,1102
22
+ jetpytools/types/generic.py,sha256=RRg2U7wxaM4Uzwc6QvsO99euCF3sqr8Kh34XKtVbgT8,1136
23
23
  jetpytools/types/supports.py,sha256=woMTv62HpcRiC5TG18U8NU5v2Q6iqcrHzQgXl7QYEws,3516
24
- jetpytools/types/utils.py,sha256=tIN6OdjrwHxb8XyQeptWh4YbOKdABPOZkKpONZ7eAv8,22877
24
+ jetpytools/types/utils.py,sha256=7r-nlUsNLZJuIYpZrHtIRO7gLuWYf_BtiR3WR9Eoxr8,23311
25
25
  jetpytools/utils/__init__.py,sha256=_rJ-mY5PsGjBfy8Fihx_FYJfAIGSrYAYzI6Td9oFh9A,83
26
- jetpytools/utils/file.py,sha256=um4ow7_UEH1UxOV74w6F1u4s0wC4zh98LrcwBYjed50,10578
26
+ jetpytools/utils/file.py,sha256=3fJxAHjIN5zdyzO0guc3jDspcs5HPG4t4cwB_ZrAhh4,10622
27
27
  jetpytools/utils/funcs.py,sha256=2qhFyLD0OLvenjzOu2wu1ZWoZGzQ8aPmvbkAI1i9Gvk,914
28
28
  jetpytools/utils/math.py,sha256=I56OeHDDJl3X8EFXMWVEiXGAD16AKcn8KVnFuP5fFes,3445
29
29
  jetpytools/utils/ranges.py,sha256=glxypgmuzauV6KCSNujNHOdWkNEUNylOUAPS618jnIg,2559
30
- jetpytools-1.7.1.dist-info/METADATA,sha256=HmlHVWQzTOvcGcFVN1BM-ljNSMWe8sXJnIzRRzOA8vg,1198
31
- jetpytools-1.7.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
32
- jetpytools-1.7.1.dist-info/licenses/LICENSE,sha256=l0PN-qDtXcgOB5aXP_nSUsvCK5V3o9pQCGsTzyZhKL0,1071
33
- jetpytools-1.7.1.dist-info/RECORD,,
30
+ jetpytools-1.7.3.dist-info/METADATA,sha256=7ALXyfpJwy9dumdXw0wkSpxGKDRZ6ccNwABSPmW3g1w,1198
31
+ jetpytools-1.7.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
32
+ jetpytools-1.7.3.dist-info/licenses/LICENSE,sha256=l0PN-qDtXcgOB5aXP_nSUsvCK5V3o9pQCGsTzyZhKL0,1071
33
+ jetpytools-1.7.3.dist-info/RECORD,,