jetpytools 1.5.0__py3-none-any.whl → 1.6.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/__init__.py +5 -5
- jetpytools/_metadata.py +4 -4
- jetpytools/enums/__init__.py +2 -2
- jetpytools/enums/base.py +9 -8
- jetpytools/enums/other.py +4 -9
- jetpytools/exceptions/__init__.py +5 -5
- jetpytools/exceptions/base.py +34 -38
- jetpytools/exceptions/enum.py +5 -4
- jetpytools/exceptions/file.py +6 -8
- jetpytools/exceptions/generic.py +8 -6
- jetpytools/exceptions/module.py +9 -8
- jetpytools/functions/__init__.py +3 -3
- jetpytools/functions/funcs.py +21 -42
- jetpytools/functions/normalize.py +42 -54
- jetpytools/functions/other.py +1 -3
- jetpytools/types/__init__.py +7 -7
- jetpytools/types/builtins.py +62 -43
- jetpytools/types/check.py +6 -9
- jetpytools/types/file.py +89 -46
- jetpytools/types/funcs.py +11 -28
- jetpytools/types/generic.py +1 -11
- jetpytools/types/supports.py +68 -52
- jetpytools/types/utils.py +102 -119
- jetpytools/utils/__init__.py +4 -4
- jetpytools/utils/file.py +94 -69
- jetpytools/utils/funcs.py +8 -13
- jetpytools/utils/math.py +26 -16
- jetpytools/utils/ranges.py +7 -11
- {jetpytools-1.5.0.dist-info → jetpytools-1.6.1.dist-info}/METADATA +10 -23
- jetpytools-1.6.1.dist-info/RECORD +33 -0
- {jetpytools-1.5.0.dist-info → jetpytools-1.6.1.dist-info}/WHEEL +1 -2
- jetpytools-1.5.0.dist-info/RECORD +0 -34
- jetpytools-1.5.0.dist-info/top_level.txt +0 -1
- {jetpytools-1.5.0.dist-info → jetpytools-1.6.1.dist-info}/licenses/LICENSE +0 -0
jetpytools/__init__.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
from .enums import *
|
|
2
|
-
from .exceptions import *
|
|
3
|
-
from .functions import *
|
|
4
|
-
from .types import *
|
|
5
|
-
from .utils import *
|
|
1
|
+
from .enums import *
|
|
2
|
+
from .exceptions import *
|
|
3
|
+
from .functions import *
|
|
4
|
+
from .types import *
|
|
5
|
+
from .utils import *
|
jetpytools/_metadata.py
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"""Collection of stuff that's useful in general python programming"""
|
|
2
2
|
|
|
3
|
-
__version__ =
|
|
3
|
+
__version__ = "1.6.1"
|
|
4
4
|
|
|
5
|
-
__author_name__, __author_email__ =
|
|
5
|
+
__author_name__, __author_email__ = "Jaded Encoding Thaumaturgy", "jaded.encoding.thaumaturgy@gmail.com"
|
|
6
6
|
__maintainer_name__, __maintainer_email__ = __author_name__, __author_email__
|
|
7
7
|
|
|
8
|
-
__author__ = f
|
|
8
|
+
__author__ = f"{__author_name__} <{__author_email__}>"
|
|
9
9
|
__maintainer__ = __author__
|
|
10
10
|
|
|
11
|
-
if __name__ ==
|
|
11
|
+
if __name__ == "__github__":
|
|
12
12
|
print(__version__)
|
jetpytools/enums/__init__.py
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
from .base import *
|
|
2
|
-
from .other import *
|
|
1
|
+
from .base import *
|
|
2
|
+
from .other import *
|
jetpytools/enums/base.py
CHANGED
|
@@ -8,9 +8,7 @@ from typing_extensions import Self
|
|
|
8
8
|
from ..exceptions import CustomValueError, NotFoundEnumValue
|
|
9
9
|
from ..types import FuncExceptT
|
|
10
10
|
|
|
11
|
-
__all__ = [
|
|
12
|
-
'CustomEnum', 'CustomIntEnum', 'CustomStrEnum'
|
|
13
|
-
]
|
|
11
|
+
__all__ = ["CustomEnum", "CustomIntEnum", "CustomStrEnum"]
|
|
14
12
|
|
|
15
13
|
|
|
16
14
|
class CustomEnum(Enum):
|
|
@@ -43,7 +41,7 @@ class CustomEnum(Enum):
|
|
|
43
41
|
return value
|
|
44
42
|
|
|
45
43
|
if value is cls:
|
|
46
|
-
raise CustomValueError(
|
|
44
|
+
raise CustomValueError("You must select a member, not pass the enum!", func_except)
|
|
47
45
|
|
|
48
46
|
try:
|
|
49
47
|
return cls(value)
|
|
@@ -57,10 +55,13 @@ class CustomEnum(Enum):
|
|
|
57
55
|
|
|
58
56
|
raise NotFoundEnumValue(
|
|
59
57
|
'The given value for "{var_name}" argument must be a valid {enum_name}, not "{value}"!\n'
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
58
|
+
"Valid values are: [{readable_enum}].",
|
|
59
|
+
func_name,
|
|
60
|
+
var_name=var_name,
|
|
61
|
+
enum_name=cls,
|
|
62
|
+
value=value,
|
|
63
|
+
readable_enum=iter([f"{x.name} ({x.value})" for x in cls]),
|
|
64
|
+
reason=value,
|
|
64
65
|
)
|
|
65
66
|
|
|
66
67
|
|
jetpytools/enums/other.py
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
from typing import overload
|
|
4
|
+
|
|
4
5
|
from typing_extensions import Self
|
|
5
6
|
|
|
6
|
-
__all__ = [
|
|
7
|
-
'Coordinate',
|
|
8
|
-
'Position',
|
|
9
|
-
'Size'
|
|
10
|
-
]
|
|
7
|
+
__all__ = ["Coordinate", "Position", "Size"]
|
|
11
8
|
|
|
12
9
|
|
|
13
10
|
class Coordinate:
|
|
@@ -24,12 +21,10 @@ class Coordinate:
|
|
|
24
21
|
"""Vertical coordinate."""
|
|
25
22
|
|
|
26
23
|
@overload
|
|
27
|
-
def __init__(self, other: tuple[int, int] | Self, /) -> None:
|
|
28
|
-
...
|
|
24
|
+
def __init__(self, other: tuple[int, int] | Self, /) -> None: ...
|
|
29
25
|
|
|
30
26
|
@overload
|
|
31
|
-
def __init__(self, x: int, y: int, /) -> None:
|
|
32
|
-
...
|
|
27
|
+
def __init__(self, x: int, y: int, /) -> None: ...
|
|
33
28
|
|
|
34
29
|
def __init__(self, x_or_self: int | tuple[int, int] | Self, y: int | None = None, /) -> None:
|
|
35
30
|
from ..exceptions import CustomValueError
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
from .base import *
|
|
2
|
-
from .enum import *
|
|
3
|
-
from .file import *
|
|
4
|
-
from .generic import *
|
|
5
|
-
from .module import *
|
|
1
|
+
from .base import *
|
|
2
|
+
from .enum import *
|
|
3
|
+
from .file import *
|
|
4
|
+
from .generic import *
|
|
5
|
+
from .module import *
|
jetpytools/exceptions/base.py
CHANGED
|
@@ -1,45 +1,43 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
import sys
|
|
4
|
-
|
|
5
4
|
from copy import deepcopy
|
|
6
5
|
from typing import TYPE_CHECKING, Any, TypeVar
|
|
7
6
|
|
|
8
7
|
from typing_extensions import Self
|
|
9
8
|
|
|
10
|
-
from ..types import MISSING, FuncExceptT,
|
|
9
|
+
from ..types import MISSING, FuncExceptT, MissingT, SupportsString
|
|
11
10
|
|
|
12
11
|
__all__ = [
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
'CustomPermissionError'
|
|
12
|
+
"CustomError",
|
|
13
|
+
"CustomIndexError",
|
|
14
|
+
"CustomKeyError",
|
|
15
|
+
"CustomNotImplementedError",
|
|
16
|
+
"CustomOverflowError",
|
|
17
|
+
"CustomPermissionError",
|
|
18
|
+
"CustomRuntimeError",
|
|
19
|
+
"CustomTypeError",
|
|
20
|
+
"CustomValueError",
|
|
23
21
|
]
|
|
24
22
|
|
|
25
23
|
|
|
26
24
|
if TYPE_CHECKING:
|
|
27
|
-
|
|
25
|
+
|
|
26
|
+
class ExceptionError(Exception):
|
|
28
27
|
__name__: str
|
|
29
28
|
__qualname__: str
|
|
30
|
-
...
|
|
31
29
|
else:
|
|
32
|
-
|
|
30
|
+
ExceptionError = Exception
|
|
33
31
|
|
|
34
32
|
|
|
35
33
|
class CustomErrorMeta(type):
|
|
36
34
|
"""Custom base exception meta class."""
|
|
37
35
|
|
|
38
36
|
def __new__(cls: type[SelfCErrorMeta], *args: Any) -> SelfCErrorMeta:
|
|
39
|
-
return CustomErrorMeta.setup_exception(type.__new__(cls, *args)) #
|
|
37
|
+
return CustomErrorMeta.setup_exception(type.__new__(cls, *args)) # pyright: ignore[reportReturnType]
|
|
40
38
|
|
|
41
39
|
@staticmethod
|
|
42
|
-
def setup_exception(exception: SelfCErrorMeta, override: str |
|
|
40
|
+
def setup_exception(exception: SelfCErrorMeta, override: str | ExceptionError | None = None) -> SelfCErrorMeta:
|
|
43
41
|
"""
|
|
44
42
|
Setup an exception for later use in CustomError.
|
|
45
43
|
|
|
@@ -55,28 +53,28 @@ class CustomErrorMeta(type):
|
|
|
55
53
|
else:
|
|
56
54
|
over_name, over_qual = override.__name__, override.__qualname__
|
|
57
55
|
|
|
58
|
-
if over_name.startswith(
|
|
56
|
+
if over_name.startswith("Custom"):
|
|
59
57
|
exception.__name__ = over_name
|
|
60
58
|
else:
|
|
61
|
-
exception.__name__ = f
|
|
59
|
+
exception.__name__ = f"Custom{over_name}"
|
|
62
60
|
|
|
63
61
|
exception.__qualname__ = over_qual
|
|
64
62
|
|
|
65
|
-
if exception.__qualname__.startswith(
|
|
63
|
+
if exception.__qualname__.startswith("Custom"):
|
|
66
64
|
exception.__qualname__ = exception.__qualname__[6:]
|
|
67
65
|
|
|
68
66
|
if sys.stdout and sys.stdout.isatty():
|
|
69
|
-
exception.__qualname__ = f
|
|
67
|
+
exception.__qualname__ = f"\033[0;31;1m{exception.__qualname__}\033[0m"
|
|
70
68
|
|
|
71
69
|
exception.__module__ = Exception.__module__
|
|
72
70
|
|
|
73
71
|
return exception
|
|
74
72
|
|
|
75
73
|
|
|
76
|
-
SelfCErrorMeta = TypeVar(
|
|
74
|
+
SelfCErrorMeta = TypeVar("SelfCErrorMeta", bound=CustomErrorMeta)
|
|
77
75
|
|
|
78
76
|
|
|
79
|
-
class CustomError(
|
|
77
|
+
class CustomError(ExceptionError, metaclass=CustomErrorMeta):
|
|
80
78
|
"""Custom base exception class."""
|
|
81
79
|
|
|
82
80
|
def __init__(
|
|
@@ -97,7 +95,7 @@ class CustomError(ExceptionT, metaclass=CustomErrorMeta):
|
|
|
97
95
|
|
|
98
96
|
super().__init__(message)
|
|
99
97
|
|
|
100
|
-
def __class_getitem__(cls, exception: str | type[
|
|
98
|
+
def __class_getitem__(cls, exception: str | type[ExceptionError] | ExceptionError) -> CustomError:
|
|
101
99
|
from warnings import warn
|
|
102
100
|
|
|
103
101
|
warn("Custom error is not subscriptable anymore. Don't use it", DeprecationWarning)
|
|
@@ -109,7 +107,7 @@ class CustomError(ExceptionT, metaclass=CustomErrorMeta):
|
|
|
109
107
|
message: SupportsString | None | MissingT = MISSING,
|
|
110
108
|
func: FuncExceptT | None | MissingT = MISSING,
|
|
111
109
|
reason: SupportsString | FuncExceptT | None | MissingT = MISSING,
|
|
112
|
-
**kwargs: Any
|
|
110
|
+
**kwargs: Any,
|
|
113
111
|
) -> Self:
|
|
114
112
|
"""
|
|
115
113
|
Copy an existing exception with defaults and instantiate a new one.
|
|
@@ -140,40 +138,38 @@ class CustomError(ExceptionT, metaclass=CustomErrorMeta):
|
|
|
140
138
|
message = self.message
|
|
141
139
|
|
|
142
140
|
if not message:
|
|
143
|
-
message =
|
|
141
|
+
message = "An error occurred!"
|
|
144
142
|
|
|
145
143
|
if self.func:
|
|
146
144
|
func_header = norm_func_name(self.func).strip()
|
|
147
145
|
|
|
148
146
|
if sys.stdout and sys.stdout.isatty():
|
|
149
|
-
func_header = f
|
|
147
|
+
func_header = f"\033[0;36m{func_header}\033[0m"
|
|
150
148
|
|
|
151
|
-
func_header = f
|
|
149
|
+
func_header = f"({func_header}) "
|
|
152
150
|
else:
|
|
153
|
-
func_header =
|
|
151
|
+
func_header = ""
|
|
154
152
|
|
|
155
153
|
if self.kwargs:
|
|
156
|
-
self.kwargs = {
|
|
157
|
-
key: norm_display_name(value) for key, value in self.kwargs.items()
|
|
158
|
-
}
|
|
154
|
+
self.kwargs = {key: norm_display_name(value) for key, value in self.kwargs.items()}
|
|
159
155
|
|
|
160
156
|
if self.reason:
|
|
161
157
|
reason = self.reason = norm_display_name(self.reason)
|
|
162
158
|
|
|
163
159
|
if reason:
|
|
164
160
|
if not isinstance(self.reason, dict):
|
|
165
|
-
reason = f
|
|
161
|
+
reason = f"({reason})"
|
|
166
162
|
|
|
167
163
|
if sys.stdout and sys.stdout.isatty():
|
|
168
|
-
reason = f
|
|
169
|
-
reason = f
|
|
164
|
+
reason = f"\033[0;33m{reason}\033[0m"
|
|
165
|
+
reason = f" {reason}"
|
|
170
166
|
else:
|
|
171
|
-
reason =
|
|
167
|
+
reason = ""
|
|
172
168
|
|
|
173
|
-
return f
|
|
169
|
+
return f"{func_header}{self.message!s}{reason}".format(**self.kwargs).strip()
|
|
174
170
|
|
|
175
171
|
|
|
176
|
-
SelfError = TypeVar(
|
|
172
|
+
SelfError = TypeVar("SelfError", bound=CustomError)
|
|
177
173
|
|
|
178
174
|
|
|
179
175
|
class CustomValueError(CustomError, ValueError):
|
jetpytools/exceptions/enum.py
CHANGED
|
@@ -2,10 +2,11 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
from .base import CustomKeyError
|
|
4
4
|
|
|
5
|
-
__all__ = [
|
|
6
|
-
'NotFoundEnumValue'
|
|
7
|
-
]
|
|
5
|
+
__all__ = ["NotFoundEnumValue", "NotFoundEnumValueError"]
|
|
8
6
|
|
|
9
7
|
|
|
10
|
-
class
|
|
8
|
+
class NotFoundEnumValueError(CustomKeyError):
|
|
11
9
|
"""Raised when you try to instantiate an Enum with unknown value"""
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
NotFoundEnumValue = NotFoundEnumValueError
|
jetpytools/exceptions/file.py
CHANGED
|
@@ -2,15 +2,13 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
from .base import CustomError, CustomPermissionError
|
|
4
4
|
|
|
5
|
-
|
|
6
5
|
__all__ = [
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
'PathIsNotADirectoryError',
|
|
6
|
+
"FileIsADirectoryError",
|
|
7
|
+
"FileNotExistsError",
|
|
8
|
+
"FilePermissionError",
|
|
9
|
+
"FileTypeMismatchError",
|
|
10
|
+
"FileWasNotFoundError",
|
|
11
|
+
"PathIsNotADirectoryError",
|
|
14
12
|
]
|
|
15
13
|
|
|
16
14
|
|
jetpytools/exceptions/generic.py
CHANGED
|
@@ -5,9 +5,7 @@ from typing import Any, Iterable
|
|
|
5
5
|
from ..types import FuncExceptT, SupportsString, T
|
|
6
6
|
from .base import CustomValueError
|
|
7
7
|
|
|
8
|
-
__all__ = [
|
|
9
|
-
'MismatchError', 'MismatchRefError'
|
|
10
|
-
]
|
|
8
|
+
__all__ = ["MismatchError", "MismatchRefError"]
|
|
11
9
|
|
|
12
10
|
|
|
13
11
|
class MismatchError(CustomValueError):
|
|
@@ -22,8 +20,12 @@ class MismatchError(CustomValueError):
|
|
|
22
20
|
return tuple(dict.fromkeys(map(cls._item_to_name, items)).keys())
|
|
23
21
|
|
|
24
22
|
def __init__(
|
|
25
|
-
self,
|
|
26
|
-
|
|
23
|
+
self,
|
|
24
|
+
func: FuncExceptT,
|
|
25
|
+
items: Iterable[Any],
|
|
26
|
+
message: SupportsString = "All items must be equal!",
|
|
27
|
+
reason: Any = "{reduced_items}",
|
|
28
|
+
**kwargs: Any,
|
|
27
29
|
) -> None:
|
|
28
30
|
super().__init__(message, func, reason, **kwargs, reduced_items=iter(self._reduce(items)))
|
|
29
31
|
|
|
@@ -35,7 +37,7 @@ class MismatchError(CustomValueError):
|
|
|
35
37
|
|
|
36
38
|
class MismatchRefError(MismatchError):
|
|
37
39
|
def __init__(
|
|
38
|
-
self, func: FuncExceptT, base: T, ref: T, message: SupportsString =
|
|
40
|
+
self, func: FuncExceptT, base: T, ref: T, message: SupportsString = "All items must be equal!", **kwargs: Any
|
|
39
41
|
) -> None:
|
|
40
42
|
super().__init__(func, [base, ref], message, **kwargs)
|
|
41
43
|
|
jetpytools/exceptions/module.py
CHANGED
|
@@ -5,19 +5,18 @@ from typing import Any
|
|
|
5
5
|
from ..types import FuncExceptT, SupportsString
|
|
6
6
|
from .base import CustomError
|
|
7
7
|
|
|
8
|
-
__all__ = [
|
|
9
|
-
'CustomImportError',
|
|
10
|
-
'DependencyNotFoundError'
|
|
11
|
-
]
|
|
8
|
+
__all__ = ["CustomImportError", "DependencyNotFoundError"]
|
|
12
9
|
|
|
13
10
|
|
|
14
11
|
class CustomImportError(CustomError, ImportError):
|
|
15
12
|
"""Raised when there's a general import error."""
|
|
16
13
|
|
|
17
14
|
def __init__(
|
|
18
|
-
self,
|
|
15
|
+
self,
|
|
16
|
+
func: FuncExceptT,
|
|
17
|
+
package: str | ImportError,
|
|
19
18
|
message: SupportsString = "Import failed for package '{package}'!",
|
|
20
|
-
**kwargs: Any
|
|
19
|
+
**kwargs: Any,
|
|
21
20
|
) -> None:
|
|
22
21
|
"""
|
|
23
22
|
:param func: Function this error was raised from.
|
|
@@ -32,8 +31,10 @@ class DependencyNotFoundError(CustomImportError):
|
|
|
32
31
|
"""Raised when there's a missing optional dependency."""
|
|
33
32
|
|
|
34
33
|
def __init__(
|
|
35
|
-
self,
|
|
34
|
+
self,
|
|
35
|
+
func: FuncExceptT,
|
|
36
|
+
package: str | ImportError,
|
|
36
37
|
message: SupportsString = "Missing dependency '{package}'!",
|
|
37
|
-
**kwargs: Any
|
|
38
|
+
**kwargs: Any,
|
|
38
39
|
) -> None:
|
|
39
40
|
super().__init__(func, package, message, **kwargs)
|
jetpytools/functions/__init__.py
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
from .funcs import *
|
|
2
|
-
from .normalize import *
|
|
3
|
-
from .other import *
|
|
1
|
+
from .funcs import *
|
|
2
|
+
from .normalize import *
|
|
3
|
+
from .other import *
|
jetpytools/functions/funcs.py
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
from typing import Any, Callable, Concatenate, overload
|
|
4
3
|
from inspect import signature
|
|
4
|
+
from typing import Any, Callable, Concatenate, overload
|
|
5
5
|
|
|
6
6
|
from ..exceptions import CustomRuntimeError, CustomValueError
|
|
7
7
|
from ..types import MISSING, KwargsT, MissingT, P, R, T
|
|
8
8
|
|
|
9
|
-
__all__ = [
|
|
10
|
-
'iterate', 'fallback', 'kwargs_fallback', 'filter_kwargs'
|
|
11
|
-
]
|
|
9
|
+
__all__ = ["fallback", "filter_kwargs", "iterate", "kwargs_fallback"]
|
|
12
10
|
|
|
13
11
|
|
|
14
12
|
def iterate(
|
|
15
|
-
base: T, function: Callable[Concatenate[T | R, P], R],
|
|
16
|
-
count: int, *args: P.args, **kwargs: P.kwargs
|
|
13
|
+
base: T, function: Callable[Concatenate[T | R, P], R], count: int, *args: P.args, **kwargs: P.kwargs
|
|
17
14
|
) -> T | R:
|
|
18
15
|
"""
|
|
19
16
|
Execute a given function over the base value multiple times.
|
|
@@ -51,28 +48,23 @@ fallback_missing = object()
|
|
|
51
48
|
|
|
52
49
|
|
|
53
50
|
@overload
|
|
54
|
-
def fallback(value: T | None, fallback: T, /) -> T:
|
|
55
|
-
...
|
|
51
|
+
def fallback(value: T | None, fallback: T, /) -> T: ...
|
|
56
52
|
|
|
57
53
|
|
|
58
54
|
@overload
|
|
59
|
-
def fallback(value: T | None, fallback0: T | None, default: T, /) -> T:
|
|
60
|
-
...
|
|
55
|
+
def fallback(value: T | None, fallback0: T | None, default: T, /) -> T: ...
|
|
61
56
|
|
|
62
57
|
|
|
63
58
|
@overload
|
|
64
|
-
def fallback(value: T | None, fallback0: T | None, fallback1: T | None, default: T, /) -> T:
|
|
65
|
-
...
|
|
59
|
+
def fallback(value: T | None, fallback0: T | None, fallback1: T | None, default: T, /) -> T: ...
|
|
66
60
|
|
|
67
61
|
|
|
68
62
|
@overload
|
|
69
|
-
def fallback(value: T | None, *fallbacks: T | None) -> T | MissingT:
|
|
70
|
-
...
|
|
63
|
+
def fallback(value: T | None, *fallbacks: T | None) -> T | MissingT: ...
|
|
71
64
|
|
|
72
65
|
|
|
73
66
|
@overload
|
|
74
|
-
def fallback(value: T | None, *fallbacks: T | None, default: T) -> T:
|
|
75
|
-
...
|
|
67
|
+
def fallback(value: T | None, *fallbacks: T | None, default: T) -> T: ...
|
|
76
68
|
|
|
77
69
|
|
|
78
70
|
def fallback(value: T | None, *fallbacks: T | None, default: Any | T = fallback_missing) -> T | MissingT:
|
|
@@ -106,47 +98,36 @@ def fallback(value: T | None, *fallbacks: T | None, default: Any | T = fallback_
|
|
|
106
98
|
elif len(fallbacks) > 3:
|
|
107
99
|
return MISSING
|
|
108
100
|
|
|
109
|
-
raise CustomRuntimeError(
|
|
101
|
+
raise CustomRuntimeError("You need to specify a default/fallback value!")
|
|
110
102
|
|
|
111
103
|
|
|
112
104
|
@overload
|
|
113
|
-
def kwargs_fallback(
|
|
114
|
-
input_value: T | None, kwargs: tuple[KwargsT, str], fallback: T
|
|
115
|
-
) -> T:
|
|
116
|
-
...
|
|
105
|
+
def kwargs_fallback(input_value: T | None, kwargs: tuple[KwargsT, str], fallback: T) -> T: ...
|
|
117
106
|
|
|
118
107
|
|
|
119
108
|
@overload
|
|
120
|
-
def kwargs_fallback(
|
|
121
|
-
input_value: T | None, kwargs: tuple[KwargsT, str], fallback0: T | None, default: T
|
|
122
|
-
) -> T:
|
|
123
|
-
...
|
|
109
|
+
def kwargs_fallback(input_value: T | None, kwargs: tuple[KwargsT, str], fallback0: T | None, default: T) -> T: ...
|
|
124
110
|
|
|
125
111
|
|
|
126
112
|
@overload
|
|
127
113
|
def kwargs_fallback(
|
|
128
|
-
input_value: T | None, kwargs: tuple[KwargsT, str], fallback0: T | None, fallback1: T | None,
|
|
129
|
-
|
|
130
|
-
) -> T:
|
|
131
|
-
...
|
|
114
|
+
input_value: T | None, kwargs: tuple[KwargsT, str], fallback0: T | None, fallback1: T | None, default: T
|
|
115
|
+
) -> T: ...
|
|
132
116
|
|
|
133
117
|
|
|
134
118
|
@overload
|
|
135
|
-
def kwargs_fallback(
|
|
136
|
-
input_value: T | None, kwargs: tuple[KwargsT, str], *fallbacks: T | None
|
|
137
|
-
) -> T | MissingT:
|
|
138
|
-
...
|
|
119
|
+
def kwargs_fallback(input_value: T | None, kwargs: tuple[KwargsT, str], *fallbacks: T | None) -> T | MissingT: ...
|
|
139
120
|
|
|
140
121
|
|
|
141
122
|
@overload
|
|
142
|
-
def kwargs_fallback(
|
|
143
|
-
input_value: T | None, kwargs: tuple[KwargsT, str], *fallbacks: T | None, default: T
|
|
144
|
-
) -> T:
|
|
145
|
-
...
|
|
123
|
+
def kwargs_fallback(input_value: T | None, kwargs: tuple[KwargsT, str], *fallbacks: T | None, default: T) -> T: ...
|
|
146
124
|
|
|
147
125
|
|
|
148
126
|
def kwargs_fallback( # type: ignore
|
|
149
|
-
value: T | None,
|
|
127
|
+
value: T | None,
|
|
128
|
+
kwargs: tuple[KwargsT, str],
|
|
129
|
+
*fallbacks: T | None,
|
|
130
|
+
default: T = fallback_missing, # type: ignore
|
|
150
131
|
) -> T | MissingT:
|
|
151
132
|
"""Utility function to return a fallback value from kwargs if value was not found or is None."""
|
|
152
133
|
|
|
@@ -154,13 +135,11 @@ def kwargs_fallback( # type: ignore
|
|
|
154
135
|
|
|
155
136
|
|
|
156
137
|
@overload
|
|
157
|
-
def filter_kwargs(func: Callable[..., Any], kwargs: dict[str, Any]) -> dict[str, Any]:
|
|
158
|
-
...
|
|
138
|
+
def filter_kwargs(func: Callable[..., Any], kwargs: dict[str, Any]) -> dict[str, Any]: ...
|
|
159
139
|
|
|
160
140
|
|
|
161
141
|
@overload
|
|
162
|
-
def filter_kwargs(func: Callable[..., Any], **kwargs: Any) -> dict[str, Any]:
|
|
163
|
-
...
|
|
142
|
+
def filter_kwargs(func: Callable[..., Any], **kwargs: Any) -> dict[str, Any]: ...
|
|
164
143
|
|
|
165
144
|
|
|
166
145
|
def filter_kwargs(func: Callable[..., Any], kwargs: dict[str, Any] | None = None, **kw: Any) -> dict[str, Any]:
|