jetpytools 1.7.3__py3-none-any.whl → 2.0.0__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 +1 -1
- jetpytools/enums/base.py +1 -7
- jetpytools/enums/other.py +5 -5
- jetpytools/exceptions/base.py +8 -31
- jetpytools/exceptions/generic.py +2 -2
- jetpytools/functions/funcs.py +18 -19
- jetpytools/functions/normalize.py +16 -18
- jetpytools/types/builtins.py +12 -70
- jetpytools/types/file.py +2 -6
- jetpytools/types/funcs.py +5 -6
- jetpytools/types/generic.py +5 -5
- jetpytools/types/supports.py +22 -39
- jetpytools/types/utils.py +407 -271
- jetpytools/utils/funcs.py +13 -10
- jetpytools/utils/math.py +3 -5
- jetpytools/utils/ranges.py +9 -50
- {jetpytools-1.7.3.dist-info → jetpytools-2.0.0.dist-info}/METADATA +3 -3
- jetpytools-2.0.0.dist-info/RECORD +33 -0
- jetpytools-1.7.3.dist-info/RECORD +0 -33
- {jetpytools-1.7.3.dist-info → jetpytools-2.0.0.dist-info}/WHEEL +0 -0
- {jetpytools-1.7.3.dist-info → jetpytools-2.0.0.dist-info}/licenses/LICENSE +0 -0
jetpytools/_metadata.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"""Collection of stuff that's useful in general python programming"""
|
|
2
2
|
|
|
3
|
-
__version__ = "
|
|
3
|
+
__version__ = "2.0.0"
|
|
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
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
from enum import Enum
|
|
4
|
-
from typing import Any
|
|
5
|
-
|
|
6
|
-
from typing_extensions import Self
|
|
4
|
+
from typing import Any, Self
|
|
7
5
|
|
|
8
6
|
from ..exceptions import CustomValueError, NotFoundEnumValue
|
|
9
7
|
from ..types import FuncExcept
|
|
@@ -68,10 +66,6 @@ class CustomEnum(Enum):
|
|
|
68
66
|
class CustomIntEnum(int, CustomEnum):
|
|
69
67
|
"""Base class for custom int enums."""
|
|
70
68
|
|
|
71
|
-
value: int
|
|
72
|
-
|
|
73
69
|
|
|
74
70
|
class CustomStrEnum(str, CustomEnum):
|
|
75
71
|
"""Base class for custom str enums."""
|
|
76
|
-
|
|
77
|
-
value: str
|
jetpytools/enums/other.py
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
from typing import overload
|
|
4
|
-
|
|
5
|
-
from typing_extensions import Self
|
|
3
|
+
from typing import Self, overload
|
|
6
4
|
|
|
7
5
|
__all__ = ["Coordinate", "Position", "Size"]
|
|
8
6
|
|
|
@@ -27,17 +25,19 @@ class Coordinate:
|
|
|
27
25
|
def __init__(self, x: int, y: int, /) -> None: ...
|
|
28
26
|
|
|
29
27
|
def __init__(self, x_or_self: int | tuple[int, int] | Self, y: int | None = None, /) -> None:
|
|
30
|
-
from ..exceptions import CustomValueError
|
|
31
|
-
|
|
32
28
|
if isinstance(x_or_self, int):
|
|
33
29
|
x = x_or_self
|
|
34
30
|
else:
|
|
35
31
|
x, y = x_or_self if isinstance(x_or_self, tuple) else (x_or_self.x, x_or_self.y)
|
|
36
32
|
|
|
37
33
|
if y is None:
|
|
34
|
+
from ..exceptions import CustomValueError
|
|
35
|
+
|
|
38
36
|
raise CustomValueError("y coordinate must be defined!", self.__class__)
|
|
39
37
|
|
|
40
38
|
if x < 0 or y < 0:
|
|
39
|
+
from ..exceptions import CustomValueError
|
|
40
|
+
|
|
41
41
|
raise CustomValueError("Values can't be negative!", self.__class__)
|
|
42
42
|
|
|
43
43
|
self.x = x
|
jetpytools/exceptions/base.py
CHANGED
|
@@ -4,7 +4,7 @@ import sys
|
|
|
4
4
|
from contextlib import AbstractContextManager
|
|
5
5
|
from copy import deepcopy
|
|
6
6
|
from types import TracebackType
|
|
7
|
-
from typing import TYPE_CHECKING, Any
|
|
7
|
+
from typing import TYPE_CHECKING, Any
|
|
8
8
|
|
|
9
9
|
from typing_extensions import Self
|
|
10
10
|
|
|
@@ -35,11 +35,13 @@ else:
|
|
|
35
35
|
class CustomErrorMeta(type):
|
|
36
36
|
"""Custom base exception meta class."""
|
|
37
37
|
|
|
38
|
-
def __new__(cls: type[
|
|
38
|
+
def __new__[MetaSelf: CustomErrorMeta](cls: type[MetaSelf], *args: Any) -> MetaSelf:
|
|
39
39
|
return CustomErrorMeta.setup_exception(super().__new__(cls, *args))
|
|
40
40
|
|
|
41
41
|
@staticmethod
|
|
42
|
-
def setup_exception
|
|
42
|
+
def setup_exception[MetaSelf: CustomErrorMeta](
|
|
43
|
+
exception: MetaSelf, override: str | ExceptionError | None = None
|
|
44
|
+
) -> MetaSelf:
|
|
43
45
|
"""
|
|
44
46
|
Setup an exception for later use in CustomError.
|
|
45
47
|
|
|
@@ -73,9 +75,6 @@ class CustomErrorMeta(type):
|
|
|
73
75
|
return exception
|
|
74
76
|
|
|
75
77
|
|
|
76
|
-
SelfCErrorMeta = TypeVar("SelfCErrorMeta", bound=CustomErrorMeta)
|
|
77
|
-
|
|
78
|
-
|
|
79
78
|
class CustomError(ExceptionError, metaclass=CustomErrorMeta):
|
|
80
79
|
"""Custom base exception class."""
|
|
81
80
|
|
|
@@ -97,13 +96,6 @@ class CustomError(ExceptionError, metaclass=CustomErrorMeta):
|
|
|
97
96
|
|
|
98
97
|
super().__init__(message)
|
|
99
98
|
|
|
100
|
-
def __class_getitem__(cls, exception: str | type[ExceptionError] | ExceptionError) -> CustomError:
|
|
101
|
-
from warnings import warn
|
|
102
|
-
|
|
103
|
-
warn("Custom error is not subscriptable anymore. Don't use it", DeprecationWarning)
|
|
104
|
-
|
|
105
|
-
return cls()
|
|
106
|
-
|
|
107
99
|
def __call__(
|
|
108
100
|
self,
|
|
109
101
|
message: SupportsString | None | MissingT = MISSING,
|
|
@@ -170,20 +162,8 @@ class CustomError(ExceptionError, metaclass=CustomErrorMeta):
|
|
|
170
162
|
|
|
171
163
|
out = f"{func_header}{self.message!s}{reason}".format(**self.kwargs).strip()
|
|
172
164
|
|
|
173
|
-
if sys.version_info < (3, 13) and hasattr(self, "__notes__"):
|
|
174
|
-
out += "\n" + "\n".join(self.__notes__)
|
|
175
|
-
|
|
176
165
|
return out
|
|
177
166
|
|
|
178
|
-
if sys.version_info < (3, 11):
|
|
179
|
-
__notes__: list[str]
|
|
180
|
-
|
|
181
|
-
def add_note(self, note: str, /) -> None:
|
|
182
|
-
if not hasattr(self, "__notes__"):
|
|
183
|
-
self.__notes__ = []
|
|
184
|
-
|
|
185
|
-
self.__notes__.append(note)
|
|
186
|
-
|
|
187
167
|
@classmethod
|
|
188
168
|
def catch(cls) -> CatchError[Self]:
|
|
189
169
|
"""
|
|
@@ -196,20 +176,17 @@ class CustomError(ExceptionError, metaclass=CustomErrorMeta):
|
|
|
196
176
|
return CatchError(cls)
|
|
197
177
|
|
|
198
178
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
class CatchError(AbstractContextManager["CatchError[SelfError]"], Generic[SelfError]):
|
|
179
|
+
class CatchError[CustomErrorT: CustomError](AbstractContextManager["CatchError[CustomErrorT]"]):
|
|
203
180
|
"""
|
|
204
181
|
Context manager for catching a specific exception type.
|
|
205
182
|
"""
|
|
206
183
|
|
|
207
|
-
error:
|
|
184
|
+
error: CustomErrorT | None
|
|
208
185
|
"""The caught exception instance, if any."""
|
|
209
186
|
tb: TracebackType | None
|
|
210
187
|
"""The traceback object associated with the caught exception."""
|
|
211
188
|
|
|
212
|
-
def __init__(self, error: type[
|
|
189
|
+
def __init__(self, error: type[CustomErrorT]) -> None:
|
|
213
190
|
self.error = None
|
|
214
191
|
self.tb = None
|
|
215
192
|
self._to_catch_error = error
|
jetpytools/exceptions/generic.py
CHANGED
|
@@ -2,7 +2,7 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
from typing import Any, Iterable
|
|
4
4
|
|
|
5
|
-
from ..types import FuncExcept, SupportsString
|
|
5
|
+
from ..types import FuncExcept, SupportsString
|
|
6
6
|
from .base import CustomValueError
|
|
7
7
|
|
|
8
8
|
__all__ = ["MismatchError", "MismatchRefError"]
|
|
@@ -36,7 +36,7 @@ class MismatchError(CustomValueError):
|
|
|
36
36
|
|
|
37
37
|
|
|
38
38
|
class MismatchRefError(MismatchError):
|
|
39
|
-
def __init__(
|
|
39
|
+
def __init__[T](
|
|
40
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)
|
jetpytools/functions/funcs.py
CHANGED
|
@@ -4,12 +4,12 @@ from inspect import signature
|
|
|
4
4
|
from typing import Any, Callable, Concatenate, overload
|
|
5
5
|
|
|
6
6
|
from ..exceptions import CustomRuntimeError, CustomValueError
|
|
7
|
-
from ..types import MISSING, KwargsT, MissingT
|
|
7
|
+
from ..types import MISSING, KwargsT, MissingT
|
|
8
8
|
|
|
9
9
|
__all__ = ["fallback", "filter_kwargs", "iterate", "kwargs_fallback"]
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
def iterate(
|
|
12
|
+
def iterate[T, **P, R](
|
|
13
13
|
base: T, function: Callable[Concatenate[T | R, P], R], count: int, *args: P.args, **kwargs: P.kwargs
|
|
14
14
|
) -> T | R:
|
|
15
15
|
"""
|
|
@@ -48,26 +48,26 @@ fallback_missing = object()
|
|
|
48
48
|
|
|
49
49
|
|
|
50
50
|
@overload
|
|
51
|
-
def fallback(value: T | None, fallback: T, /) -> T: ...
|
|
51
|
+
def fallback[T](value: T | None, fallback: T, /) -> T: ...
|
|
52
52
|
|
|
53
53
|
|
|
54
54
|
@overload
|
|
55
|
-
def fallback(value: T | None, fallback0: T | None, default: T, /) -> T: ...
|
|
55
|
+
def fallback[T](value: T | None, fallback0: T | None, default: T, /) -> T: ...
|
|
56
56
|
|
|
57
57
|
|
|
58
58
|
@overload
|
|
59
|
-
def fallback(value: T | None, fallback0: T | None, fallback1: T | None, default: T, /) -> T: ...
|
|
59
|
+
def fallback[T](value: T | None, fallback0: T | None, fallback1: T | None, default: T, /) -> T: ...
|
|
60
60
|
|
|
61
61
|
|
|
62
62
|
@overload
|
|
63
|
-
def fallback(value: T | None, *fallbacks: T | None) -> T | MissingT: ...
|
|
63
|
+
def fallback[T](value: T | None, *fallbacks: T | None) -> T | MissingT: ...
|
|
64
64
|
|
|
65
65
|
|
|
66
66
|
@overload
|
|
67
|
-
def fallback(value: T | None, *fallbacks: T | None, default: T) -> T: ...
|
|
67
|
+
def fallback[T](value: T | None, *fallbacks: T | None, default: T) -> T: ...
|
|
68
68
|
|
|
69
69
|
|
|
70
|
-
def fallback(value: T | None, *fallbacks: T | None, default: Any | T = fallback_missing) -> T | MissingT:
|
|
70
|
+
def fallback[T](value: T | None, *fallbacks: T | None, default: Any | T = fallback_missing) -> T | MissingT:
|
|
71
71
|
"""
|
|
72
72
|
Utility function that returns a value or a fallback if the value is None.
|
|
73
73
|
|
|
@@ -102,32 +102,31 @@ def fallback(value: T | None, *fallbacks: T | None, default: Any | T = fallback_
|
|
|
102
102
|
|
|
103
103
|
|
|
104
104
|
@overload
|
|
105
|
-
def kwargs_fallback(input_value: T | None, kwargs: tuple[KwargsT, str], fallback: T) -> T: ...
|
|
105
|
+
def kwargs_fallback[T](input_value: T | None, kwargs: tuple[KwargsT, str], fallback: T, /) -> T: ...
|
|
106
106
|
|
|
107
107
|
|
|
108
108
|
@overload
|
|
109
|
-
def kwargs_fallback(input_value: T | None, kwargs: tuple[KwargsT, str], fallback0: T | None, default: T) -> T: ...
|
|
109
|
+
def kwargs_fallback[T](input_value: T | None, kwargs: tuple[KwargsT, str], fallback0: T | None, default: T, /) -> T: ...
|
|
110
110
|
|
|
111
111
|
|
|
112
112
|
@overload
|
|
113
|
-
def kwargs_fallback(
|
|
114
|
-
input_value: T | None, kwargs: tuple[KwargsT, str], fallback0: T | None, fallback1: T | None, default: T
|
|
113
|
+
def kwargs_fallback[T](
|
|
114
|
+
input_value: T | None, kwargs: tuple[KwargsT, str], fallback0: T | None, fallback1: T | None, default: T, /
|
|
115
115
|
) -> T: ...
|
|
116
116
|
|
|
117
117
|
|
|
118
118
|
@overload
|
|
119
|
-
def kwargs_fallback(input_value: T | None, kwargs: tuple[KwargsT, str], *fallbacks: T | None) -> T | MissingT: ...
|
|
119
|
+
def kwargs_fallback[T](input_value: T | None, kwargs: tuple[KwargsT, str], /, *fallbacks: T | None) -> T | MissingT: ...
|
|
120
120
|
|
|
121
121
|
|
|
122
122
|
@overload
|
|
123
|
-
def kwargs_fallback
|
|
123
|
+
def kwargs_fallback[T](
|
|
124
|
+
input_value: T | None, kwargs: tuple[KwargsT, str], /, *fallbacks: T | None, default: T
|
|
125
|
+
) -> T: ...
|
|
124
126
|
|
|
125
127
|
|
|
126
|
-
def kwargs_fallback(
|
|
127
|
-
value: T | None,
|
|
128
|
-
kwargs: tuple[KwargsT, str],
|
|
129
|
-
*fallbacks: T | None,
|
|
130
|
-
default: T = fallback_missing, # type: ignore
|
|
128
|
+
def kwargs_fallback[T](
|
|
129
|
+
value: T | None, kwargs: tuple[KwargsT, str], *fallbacks: T | None, default: Any | T = fallback_missing
|
|
131
130
|
) -> T | MissingT:
|
|
132
131
|
"""Utility function to return a fallback value from kwargs if value was not found or is None."""
|
|
133
132
|
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
import sys
|
|
4
3
|
from fractions import Fraction
|
|
5
|
-
from typing import Any, Callable, Iterable, Iterator, Sequence, overload
|
|
4
|
+
from typing import Any, Callable, Iterable, Iterator, Protocol, Sequence, overload, runtime_checkable
|
|
6
5
|
|
|
7
6
|
from ..exceptions import CustomOverflowError
|
|
8
|
-
from ..types import SoftRange, SoftRangeN, SoftRangesN, StrictRange, SupportsString,
|
|
7
|
+
from ..types import SoftRange, SoftRangeN, SoftRangesN, StrictRange, SupportsString, is_soft_range_n
|
|
9
8
|
|
|
10
9
|
__all__ = [
|
|
11
10
|
"flatten",
|
|
@@ -22,14 +21,14 @@ __all__ = [
|
|
|
22
21
|
|
|
23
22
|
|
|
24
23
|
@overload
|
|
25
|
-
def normalize_seq(val: T | Sequence[T], length: int) -> list[T]: ...
|
|
24
|
+
def normalize_seq[T](val: T | Sequence[T], length: int) -> list[T]: ...
|
|
26
25
|
|
|
27
26
|
|
|
28
27
|
@overload
|
|
29
28
|
def normalize_seq(val: Any, length: int) -> list[Any]: ...
|
|
30
29
|
|
|
31
30
|
|
|
32
|
-
def normalize_seq(val: T | Sequence[T], length: int) -> list[T]:
|
|
31
|
+
def normalize_seq[T](val: T | Sequence[T], length: int) -> list[T]:
|
|
33
32
|
"""
|
|
34
33
|
Normalize a sequence of values.
|
|
35
34
|
|
|
@@ -49,28 +48,23 @@ def normalize_seq(val: T | Sequence[T], length: int) -> list[T]:
|
|
|
49
48
|
|
|
50
49
|
|
|
51
50
|
@overload
|
|
52
|
-
def to_arr(val: T | Iterable[T]) -> list[T]: ...
|
|
51
|
+
def to_arr[T](val: T | Iterable[T]) -> list[T]: ...
|
|
53
52
|
|
|
54
53
|
|
|
55
54
|
@overload
|
|
56
55
|
def to_arr(val: Any) -> list[Any]: ...
|
|
57
56
|
|
|
58
57
|
|
|
59
|
-
def to_arr(val: Any
|
|
58
|
+
def to_arr(val: Any) -> list[Any]:
|
|
60
59
|
"""
|
|
61
60
|
Normalize any value to a list.
|
|
62
61
|
Bytes and str are not considered iterable and will not be flattened.
|
|
63
62
|
"""
|
|
64
|
-
if sub:
|
|
65
|
-
import warnings
|
|
66
|
-
|
|
67
|
-
warnings.warn("sub is deprecated.", DeprecationWarning)
|
|
68
|
-
|
|
69
63
|
return list(val) if (isinstance(val, Iterable) and not isinstance(val, (str, bytes))) else [val]
|
|
70
64
|
|
|
71
65
|
|
|
72
66
|
@overload
|
|
73
|
-
def flatten(items: Iterable[Iterable[T]]) -> Iterator[T]: ...
|
|
67
|
+
def flatten[T](items: Iterable[Iterable[T]]) -> Iterator[T]: ...
|
|
74
68
|
|
|
75
69
|
|
|
76
70
|
@overload
|
|
@@ -239,10 +233,7 @@ def normalize_ranges(
|
|
|
239
233
|
out.append((start, end))
|
|
240
234
|
|
|
241
235
|
if exceptions:
|
|
242
|
-
|
|
243
|
-
raise ExceptionGroup("Multiple exceptions occurred!", exceptions) # noqa: F821
|
|
244
|
-
|
|
245
|
-
raise Exception(exceptions)
|
|
236
|
+
raise ExceptionGroup("Multiple exceptions occurred!", exceptions)
|
|
246
237
|
|
|
247
238
|
return normalize_list_to_ranges(
|
|
248
239
|
[x for start, end in out for x in range(start, end + (not exclusive))], exclusive=exclusive
|
|
@@ -259,6 +250,13 @@ def invert_ranges(
|
|
|
259
250
|
return normalize_list_to_ranges({*range(lengtha)} - b_frames, exclusive=exclusive)
|
|
260
251
|
|
|
261
252
|
|
|
253
|
+
@runtime_checkable
|
|
254
|
+
class _HasSelfAttr(Protocol):
|
|
255
|
+
__self__: type | object
|
|
256
|
+
|
|
257
|
+
def __call__(self, *args: Any, **kwds: Any) -> Any: ...
|
|
258
|
+
|
|
259
|
+
|
|
262
260
|
def norm_func_name(func_name: SupportsString | Callable[..., Any]) -> str:
|
|
263
261
|
"""Normalize a class, function, or other object to obtain its name"""
|
|
264
262
|
|
|
@@ -275,7 +273,7 @@ def norm_func_name(func_name: SupportsString | Callable[..., Any]) -> str:
|
|
|
275
273
|
elif hasattr(func_name, "__qualname__"):
|
|
276
274
|
func_name = func.__qualname__
|
|
277
275
|
|
|
278
|
-
if
|
|
276
|
+
if isinstance(func, _HasSelfAttr):
|
|
279
277
|
func = func.__self__ if isinstance(func.__self__, type) else func.__self__.__class__
|
|
280
278
|
func_name = f"{func.__name__}.{func_name}"
|
|
281
279
|
|
jetpytools/types/builtins.py
CHANGED
|
@@ -1,30 +1,10 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
from typing import Any,
|
|
3
|
+
from typing import Any, Sequence, SupportsFloat, SupportsIndex
|
|
4
4
|
|
|
5
5
|
__all__ = [
|
|
6
|
-
"F0",
|
|
7
|
-
"F1",
|
|
8
|
-
"F2",
|
|
9
|
-
"P0",
|
|
10
|
-
"P1",
|
|
11
|
-
"P2",
|
|
12
|
-
"R0",
|
|
13
|
-
"R1",
|
|
14
|
-
"R2",
|
|
15
|
-
"T0",
|
|
16
|
-
"T1",
|
|
17
|
-
"T2",
|
|
18
6
|
"ByteData",
|
|
19
|
-
"F",
|
|
20
7
|
"KwargsT",
|
|
21
|
-
"Nb",
|
|
22
|
-
"P",
|
|
23
|
-
"R",
|
|
24
|
-
"R0_co",
|
|
25
|
-
"R1_co",
|
|
26
|
-
"R_co",
|
|
27
|
-
"R_contra",
|
|
28
8
|
"SimpleByteData",
|
|
29
9
|
"SimpleByteDataArray",
|
|
30
10
|
"SingleOrArr",
|
|
@@ -35,61 +15,23 @@ __all__ = [
|
|
|
35
15
|
"SoftRangeN",
|
|
36
16
|
"SoftRangesN",
|
|
37
17
|
"StrictRange",
|
|
38
|
-
"T",
|
|
39
|
-
"T0_co",
|
|
40
|
-
"T1_co",
|
|
41
|
-
"T_co",
|
|
42
|
-
"T_contra",
|
|
43
18
|
]
|
|
44
19
|
|
|
45
|
-
|
|
20
|
+
type StrictRange = tuple[int, int]
|
|
21
|
+
type SoftRange = int | StrictRange | Sequence[int]
|
|
46
22
|
|
|
47
|
-
|
|
48
|
-
T0 = TypeVar("T0")
|
|
49
|
-
T1 = TypeVar("T1")
|
|
50
|
-
T2 = TypeVar("T2")
|
|
23
|
+
type SoftRangeN = int | tuple[int | None, int | None] | None
|
|
51
24
|
|
|
52
|
-
|
|
53
|
-
F0 = TypeVar("F0", bound=Callable[..., Any])
|
|
54
|
-
F1 = TypeVar("F1", bound=Callable[..., Any])
|
|
55
|
-
F2 = TypeVar("F2", bound=Callable[..., Any])
|
|
25
|
+
type SoftRangesN = Sequence[SoftRangeN]
|
|
56
26
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
27
|
+
type SingleOrArr[T] = T | list[T]
|
|
28
|
+
type SingleOrSeq[T] = T | Sequence[T]
|
|
29
|
+
type SingleOrArrOpt[T] = SingleOrArr[T] | None
|
|
30
|
+
type SingleOrSeqOpt[T] = SingleOrSeq[T] | None
|
|
61
31
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
R1 = TypeVar("R1")
|
|
65
|
-
R2 = TypeVar("R2")
|
|
32
|
+
type SimpleByteData = str | bytes | bytearray
|
|
33
|
+
type SimpleByteDataArray = SimpleByteData | Sequence[SimpleByteData]
|
|
66
34
|
|
|
67
|
-
|
|
68
|
-
T0_co = TypeVar("T0_co", covariant=True)
|
|
69
|
-
T1_co = TypeVar("T1_co", covariant=True)
|
|
70
|
-
|
|
71
|
-
R_co = TypeVar("R_co", covariant=True)
|
|
72
|
-
R0_co = TypeVar("R0_co", covariant=True)
|
|
73
|
-
R1_co = TypeVar("R1_co", covariant=True)
|
|
74
|
-
|
|
75
|
-
T_contra = TypeVar("T_contra", contravariant=True)
|
|
76
|
-
R_contra = TypeVar("R_contra", contravariant=True)
|
|
77
|
-
|
|
78
|
-
StrictRange: TypeAlias = tuple[int, int]
|
|
79
|
-
SoftRange: TypeAlias = int | StrictRange | Sequence[int]
|
|
80
|
-
|
|
81
|
-
SoftRangeN: TypeAlias = int | tuple[int | None, int | None] | None
|
|
82
|
-
|
|
83
|
-
SoftRangesN: TypeAlias = Sequence[SoftRangeN]
|
|
84
|
-
|
|
85
|
-
SingleOrArr = Union[T, list[T]]
|
|
86
|
-
SingleOrSeq = Union[T, Sequence[T]]
|
|
87
|
-
SingleOrArrOpt = Union[SingleOrArr[T], None]
|
|
88
|
-
SingleOrSeqOpt = Union[SingleOrSeq[T], None]
|
|
89
|
-
|
|
90
|
-
SimpleByteData: TypeAlias = str | bytes | bytearray
|
|
91
|
-
SimpleByteDataArray = Union[SimpleByteData, Sequence[SimpleByteData]]
|
|
92
|
-
|
|
93
|
-
ByteData: TypeAlias = SupportsFloat | SupportsIndex | SimpleByteData | memoryview
|
|
35
|
+
type ByteData = SupportsFloat | SupportsIndex | SimpleByteData | memoryview
|
|
94
36
|
|
|
95
37
|
KwargsT = dict[str, Any]
|
jetpytools/types/file.py
CHANGED
|
@@ -4,8 +4,7 @@ import fnmatch
|
|
|
4
4
|
import shutil
|
|
5
5
|
from os import X_OK, PathLike, access, listdir, path, walk
|
|
6
6
|
from pathlib import Path
|
|
7
|
-
from
|
|
8
|
-
from typing import TYPE_CHECKING, Any, Callable, Iterable, Literal, TypeAlias, Union
|
|
7
|
+
from typing import TYPE_CHECKING, Any, Callable, Iterable, Literal, TypeAlias
|
|
9
8
|
|
|
10
9
|
from typing_extensions import Self
|
|
11
10
|
|
|
@@ -105,9 +104,6 @@ OpenBinaryMode: TypeAlias = OpenBinaryModeUpdating | OpenBinaryModeReading | Ope
|
|
|
105
104
|
class SPath(Path):
|
|
106
105
|
"""Modified version of pathlib.Path"""
|
|
107
106
|
|
|
108
|
-
if version_info < (3, 12):
|
|
109
|
-
_flavour = type(Path())._flavour # type: ignore
|
|
110
|
-
|
|
111
107
|
if TYPE_CHECKING:
|
|
112
108
|
|
|
113
109
|
def __new__(cls, *args: SPathLike, **kwargs: Any) -> Self: ...
|
|
@@ -245,4 +241,4 @@ class SPath(Path):
|
|
|
245
241
|
return access(self.to_str(), X_OK)
|
|
246
242
|
|
|
247
243
|
|
|
248
|
-
SPathLike =
|
|
244
|
+
type SPathLike = str | PathLike[str]
|
jetpytools/types/funcs.py
CHANGED
|
@@ -3,9 +3,8 @@ from __future__ import annotations
|
|
|
3
3
|
from functools import wraps
|
|
4
4
|
from typing import TYPE_CHECKING, Any, Callable, Iterable, Iterator, SupportsIndex, TypeAlias
|
|
5
5
|
|
|
6
|
-
from typing_extensions import
|
|
6
|
+
from typing_extensions import TypeIs
|
|
7
7
|
|
|
8
|
-
from .builtins import P, T
|
|
9
8
|
from .supports import SupportsString
|
|
10
9
|
|
|
11
10
|
__all__ = ["Sentinel", "SentinelT", "StrList"]
|
|
@@ -49,24 +48,24 @@ class StrList(list[SupportsString]):
|
|
|
49
48
|
|
|
50
49
|
|
|
51
50
|
class SentinelDispatcher:
|
|
52
|
-
def check(self, ret_value: T, cond: bool) -> T | SentinelDispatcher:
|
|
51
|
+
def check[T](self, ret_value: T, cond: bool) -> T | SentinelDispatcher:
|
|
53
52
|
return ret_value if cond else self
|
|
54
53
|
|
|
55
|
-
def check_cb(self, callback: Callable[P, tuple[T, bool]]) -> Callable[P, T | SentinelDispatcher]:
|
|
54
|
+
def check_cb[T, **P](self, callback: Callable[P, tuple[T, bool]]) -> Callable[P, T | SentinelDispatcher]:
|
|
56
55
|
@wraps(callback)
|
|
57
56
|
def _wrap(*args: P.args, **kwargs: P.kwargs) -> T | SentinelDispatcher:
|
|
58
57
|
return self.check(*callback(*args, **kwargs))
|
|
59
58
|
|
|
60
59
|
return _wrap
|
|
61
60
|
|
|
62
|
-
def filter(self, items: Iterable[T |
|
|
61
|
+
def filter[T](self, items: Iterable[T | SentinelDispatcher]) -> Iterator[T]:
|
|
63
62
|
for item in items:
|
|
64
63
|
if isinstance(item, SentinelDispatcher):
|
|
65
64
|
continue
|
|
66
65
|
yield item
|
|
67
66
|
|
|
68
67
|
@classmethod
|
|
69
|
-
def filter_multi(cls, items: Iterable[T |
|
|
68
|
+
def filter_multi[T](cls, items: Iterable[T | SentinelDispatcher], *sentinels: SentinelDispatcher) -> Iterator[T]:
|
|
70
69
|
def _in_sentinels(it: Any) -> TypeIs[SentinelDispatcher]:
|
|
71
70
|
return it in sentinels
|
|
72
71
|
|
jetpytools/types/generic.py
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
from enum import Enum, auto
|
|
4
|
-
from typing import Any, Callable, Literal
|
|
4
|
+
from typing import Any, Callable, Literal
|
|
5
5
|
|
|
6
|
-
from .builtins import
|
|
6
|
+
from .builtins import SingleOrArr, SingleOrArrOpt
|
|
7
7
|
from .supports import SupportsString
|
|
8
8
|
|
|
9
9
|
__all__ = ["MISSING", "DataType", "FuncExcept", "FuncExceptT", "MissingT", "PassthroughC", "StrArr", "StrArrOpt"]
|
|
@@ -13,10 +13,10 @@ class _MissingType(Enum):
|
|
|
13
13
|
MISSING = auto()
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
MissingT
|
|
16
|
+
type MissingT = Literal[_MissingType.MISSING]
|
|
17
17
|
MISSING = _MissingType.MISSING
|
|
18
18
|
|
|
19
|
-
DataType =
|
|
19
|
+
type DataType = str | bytes | bytearray | SupportsString
|
|
20
20
|
|
|
21
21
|
FuncExcept = str | Callable[..., Any] | tuple[Callable[..., Any] | str, str]
|
|
22
22
|
"""
|
|
@@ -40,4 +40,4 @@ FuncExceptT = FuncExcept
|
|
|
40
40
|
StrArr = SingleOrArr[SupportsString]
|
|
41
41
|
StrArrOpt = SingleOrArrOpt[SupportsString]
|
|
42
42
|
|
|
43
|
-
PassthroughC = Callable[[F], F]
|
|
43
|
+
type PassthroughC[F: Callable[..., Any]] = Callable[[F], F]
|