jetpytools 1.7.4__tar.gz → 2.0.0__tar.gz

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.

Files changed (38) hide show
  1. {jetpytools-1.7.4 → jetpytools-2.0.0}/PKG-INFO +3 -3
  2. {jetpytools-1.7.4 → jetpytools-2.0.0}/jetpytools/_metadata.py +1 -1
  3. {jetpytools-1.7.4 → jetpytools-2.0.0}/jetpytools/enums/base.py +1 -7
  4. {jetpytools-1.7.4 → jetpytools-2.0.0}/jetpytools/enums/other.py +5 -5
  5. {jetpytools-1.7.4 → jetpytools-2.0.0}/jetpytools/exceptions/base.py +8 -31
  6. {jetpytools-1.7.4 → jetpytools-2.0.0}/jetpytools/exceptions/generic.py +2 -2
  7. {jetpytools-1.7.4 → jetpytools-2.0.0}/jetpytools/functions/funcs.py +18 -19
  8. {jetpytools-1.7.4 → jetpytools-2.0.0}/jetpytools/functions/normalize.py +16 -18
  9. jetpytools-2.0.0/jetpytools/types/builtins.py +37 -0
  10. {jetpytools-1.7.4 → jetpytools-2.0.0}/jetpytools/types/file.py +2 -6
  11. {jetpytools-1.7.4 → jetpytools-2.0.0}/jetpytools/types/funcs.py +5 -6
  12. {jetpytools-1.7.4 → jetpytools-2.0.0}/jetpytools/types/generic.py +5 -5
  13. {jetpytools-1.7.4 → jetpytools-2.0.0}/jetpytools/types/supports.py +22 -39
  14. jetpytools-2.0.0/jetpytools/types/utils.py +850 -0
  15. jetpytools-2.0.0/jetpytools/utils/funcs.py +33 -0
  16. {jetpytools-1.7.4 → jetpytools-2.0.0}/jetpytools/utils/math.py +3 -5
  17. jetpytools-2.0.0/jetpytools/utils/ranges.py +44 -0
  18. {jetpytools-1.7.4 → jetpytools-2.0.0}/pyproject.toml +5 -5
  19. jetpytools-1.7.4/jetpytools/types/builtins.py +0 -95
  20. jetpytools-1.7.4/jetpytools/types/utils.py +0 -721
  21. jetpytools-1.7.4/jetpytools/utils/funcs.py +0 -30
  22. jetpytools-1.7.4/jetpytools/utils/ranges.py +0 -85
  23. {jetpytools-1.7.4 → jetpytools-2.0.0}/.gitignore +0 -0
  24. {jetpytools-1.7.4 → jetpytools-2.0.0}/LICENSE +0 -0
  25. {jetpytools-1.7.4 → jetpytools-2.0.0}/README.md +0 -0
  26. {jetpytools-1.7.4 → jetpytools-2.0.0}/jetpytools/__init__.py +0 -0
  27. {jetpytools-1.7.4 → jetpytools-2.0.0}/jetpytools/enums/__init__.py +0 -0
  28. {jetpytools-1.7.4 → jetpytools-2.0.0}/jetpytools/exceptions/__init__.py +0 -0
  29. {jetpytools-1.7.4 → jetpytools-2.0.0}/jetpytools/exceptions/enum.py +0 -0
  30. {jetpytools-1.7.4 → jetpytools-2.0.0}/jetpytools/exceptions/file.py +0 -0
  31. {jetpytools-1.7.4 → jetpytools-2.0.0}/jetpytools/exceptions/module.py +0 -0
  32. {jetpytools-1.7.4 → jetpytools-2.0.0}/jetpytools/functions/__init__.py +0 -0
  33. {jetpytools-1.7.4 → jetpytools-2.0.0}/jetpytools/functions/other.py +0 -0
  34. {jetpytools-1.7.4 → jetpytools-2.0.0}/jetpytools/py.typed +0 -0
  35. {jetpytools-1.7.4 → jetpytools-2.0.0}/jetpytools/types/__init__.py +0 -0
  36. {jetpytools-1.7.4 → jetpytools-2.0.0}/jetpytools/types/check.py +0 -0
  37. {jetpytools-1.7.4 → jetpytools-2.0.0}/jetpytools/utils/__init__.py +0 -0
  38. {jetpytools-1.7.4 → jetpytools-2.0.0}/jetpytools/utils/file.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: jetpytools
3
- Version: 1.7.4
3
+ Version: 2.0.0
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
@@ -1,6 +1,6 @@
1
1
  """Collection of stuff that's useful in general python programming"""
2
2
 
3
- __version__ = "1.7.4"
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__
@@ -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
@@ -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
@@ -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, Generic, TypeVar
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[SelfCErrorMeta], *args: Any) -> SelfCErrorMeta:
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(exception: SelfCErrorMeta, override: str | ExceptionError | None = None) -> SelfCErrorMeta:
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
- SelfError = TypeVar("SelfError", bound=CustomError)
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: SelfError | None
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[SelfError]) -> None:
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
@@ -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, T
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)
@@ -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, P, R, T
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(input_value: T | None, kwargs: tuple[KwargsT, str], *fallbacks: T | None, default: T) -> T: ...
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( # type: ignore
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, T, is_soft_range_n
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, *, sub: Any = []) -> list[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
- if sys.version_info >= (3, 11):
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 callable(func) and hasattr(func, "__self__"):
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
 
@@ -0,0 +1,37 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any, Sequence, SupportsFloat, SupportsIndex
4
+
5
+ __all__ = [
6
+ "ByteData",
7
+ "KwargsT",
8
+ "SimpleByteData",
9
+ "SimpleByteDataArray",
10
+ "SingleOrArr",
11
+ "SingleOrArrOpt",
12
+ "SingleOrSeq",
13
+ "SingleOrSeqOpt",
14
+ "SoftRange",
15
+ "SoftRangeN",
16
+ "SoftRangesN",
17
+ "StrictRange",
18
+ ]
19
+
20
+ type StrictRange = tuple[int, int]
21
+ type SoftRange = int | StrictRange | Sequence[int]
22
+
23
+ type SoftRangeN = int | tuple[int | None, int | None] | None
24
+
25
+ type SoftRangesN = Sequence[SoftRangeN]
26
+
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
31
+
32
+ type SimpleByteData = str | bytes | bytearray
33
+ type SimpleByteDataArray = SimpleByteData | Sequence[SimpleByteData]
34
+
35
+ type ByteData = SupportsFloat | SupportsIndex | SimpleByteData | memoryview
36
+
37
+ KwargsT = dict[str, Any]
@@ -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 sys import version_info
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 = Union[str, PathLike[str], Path, SPath]
244
+ type SPathLike = str | PathLike[str]
@@ -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 Self, TypeIs
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 | Self]) -> Iterator[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 | Self], *sentinels: Self) -> Iterator[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
 
@@ -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, TypeAlias, Union
4
+ from typing import Any, Callable, Literal
5
5
 
6
- from .builtins import F, SingleOrArr, SingleOrArrOpt
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: TypeAlias = Literal[_MissingType.MISSING]
16
+ type MissingT = Literal[_MissingType.MISSING]
17
17
  MISSING = _MissingType.MISSING
18
18
 
19
- DataType = Union[str, bytes, bytearray, SupportsString]
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]
@@ -1,20 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  from abc import abstractmethod
4
- from typing import (
5
- Any,
6
- Callable,
7
- Iterable,
8
- Protocol,
9
- SupportsFloat,
10
- SupportsIndex,
11
- TypeAlias,
12
- TypeVar,
13
- overload,
14
- runtime_checkable,
15
- )
16
-
17
- from .builtins import T0, T1, T2, T_co, T_contra
4
+ from typing import Any, Callable, Iterable, Protocol, SupportsFloat, SupportsIndex, TypeVar, overload, runtime_checkable
18
5
 
19
6
  __all__ = [
20
7
  "ComparatorFunc",
@@ -36,17 +23,13 @@ __all__ = [
36
23
  ]
37
24
 
38
25
 
39
- _KT = TypeVar("_KT")
40
- _VT_co = TypeVar("_VT_co", covariant=True)
41
-
42
-
43
26
  @runtime_checkable
44
- class SupportsAdd(Protocol[T_contra, T_co]):
27
+ class SupportsAdd[T_contra, T_co](Protocol):
45
28
  def __add__(self, x: T_contra, /) -> T_co: ...
46
29
 
47
30
 
48
31
  @runtime_checkable
49
- class SupportsRAdd(Protocol[T_contra, T_co]):
32
+ class SupportsRAdd[T_contra, T_co](Protocol):
50
33
  def __radd__(self, x: T_contra, /) -> T_co: ...
51
34
 
52
35
 
@@ -68,22 +51,22 @@ class SupportsString(Protocol):
68
51
 
69
52
 
70
53
  @runtime_checkable
71
- class SupportsDunderLT(Protocol[T_contra]):
54
+ class SupportsDunderLT[T_contra](Protocol):
72
55
  def __lt__(self, other: T_contra) -> bool: ...
73
56
 
74
57
 
75
58
  @runtime_checkable
76
- class SupportsDunderGT(Protocol[T_contra]):
59
+ class SupportsDunderGT[T_contra](Protocol):
77
60
  def __gt__(self, other: T_contra) -> bool: ...
78
61
 
79
62
 
80
63
  @runtime_checkable
81
- class SupportsDunderLE(Protocol[T_contra]):
64
+ class SupportsDunderLE[T_contra](Protocol):
82
65
  def __le__(self, other: T_contra) -> bool: ...
83
66
 
84
67
 
85
68
  @runtime_checkable
86
- class SupportsDunderGE(Protocol[T_contra]):
69
+ class SupportsDunderGE[T_contra](Protocol):
87
70
  def __ge__(self, other: T_contra) -> bool: ...
88
71
 
89
72
 
@@ -93,7 +76,7 @@ class SupportsAllComparisons(
93
76
  ): ...
94
77
 
95
78
 
96
- SupportsRichComparison: TypeAlias = SupportsDunderLT[Any] | SupportsDunderGT[Any]
79
+ type SupportsRichComparison = SupportsDunderLT[Any] | SupportsDunderGT[Any]
97
80
  SupportsRichComparisonT = TypeVar("SupportsRichComparisonT", bound=SupportsRichComparison)
98
81
 
99
82
 
@@ -109,7 +92,7 @@ class ComparatorFunc(Protocol):
109
92
  ) -> SupportsRichComparisonT: ...
110
93
 
111
94
  @overload
112
- def __call__(self, arg1: T0, arg2: T0, /, *_args: T0, key: Callable[[T0], SupportsRichComparison]) -> T0: ...
95
+ def __call__[T](self, arg1: T, arg2: T, /, *_args: T, key: Callable[[T], SupportsRichComparison]) -> T: ...
113
96
 
114
97
  @overload
115
98
  def __call__(
@@ -117,27 +100,27 @@ class ComparatorFunc(Protocol):
117
100
  ) -> SupportsRichComparisonT: ...
118
101
 
119
102
  @overload
120
- def __call__(self, iterable: Iterable[T0], /, *, key: Callable[[T0], SupportsRichComparison]) -> T0: ...
103
+ def __call__[T](self, iterable: Iterable[T], /, *, key: Callable[[T], SupportsRichComparison]) -> T: ...
121
104
 
122
105
  @overload
123
- def __call__(
124
- self, iterable: Iterable[SupportsRichComparisonT], /, *, key: None = ..., default: T0
125
- ) -> SupportsRichComparisonT | T0: ...
106
+ def __call__[T, SupportsRichComparisonT: SupportsRichComparison](
107
+ self, iterable: Iterable[SupportsRichComparisonT], /, *, key: None = ..., default: T
108
+ ) -> SupportsRichComparisonT | T: ...
126
109
 
127
110
  @overload
128
- def __call__(
129
- self, iterable: Iterable[T1], /, *, key: Callable[[T1], SupportsRichComparison], default: T2
130
- ) -> T1 | T2: ...
111
+ def __call__[T0, T1](
112
+ self, iterable: Iterable[T0], /, *, key: Callable[[T0], SupportsRichComparison], default: T1
113
+ ) -> T0 | T1: ...
131
114
 
132
115
 
133
- class SupportsIndexing(Protocol[_VT_co]):
134
- def __getitem__(self, k: int) -> _VT_co: ...
116
+ class SupportsIndexing[T](Protocol):
117
+ def __getitem__(self, k: int) -> T: ...
135
118
 
136
119
 
137
- class SupportsKeysAndGetItem(Protocol[_KT, _VT_co]):
138
- def keys(self) -> Iterable[_KT]: ...
120
+ class SupportsKeysAndGetItem[KT, VT](Protocol):
121
+ def keys(self) -> Iterable[KT]: ...
139
122
 
140
- def __getitem__(self, k: _KT) -> _VT_co: ...
123
+ def __getitem__(self, k: KT) -> VT: ...
141
124
 
142
125
 
143
- SupportsFloatOrIndex: TypeAlias = SupportsFloat | SupportsIndex
126
+ type SupportsFloatOrIndex = SupportsFloat | SupportsIndex