hunterMakesPy 0.7.2__tar.gz → 0.7.3__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.
- {huntermakespy-0.7.2 → huntermakespy-0.7.3}/PKG-INFO +1 -1
- {huntermakespy-0.7.2 → huntermakespy-0.7.3}/hunterMakesPy/parseParameters.py +56 -67
- {huntermakespy-0.7.2 → huntermakespy-0.7.3}/hunterMakesPy/theTypes.py +2 -0
- {huntermakespy-0.7.2 → huntermakespy-0.7.3}/hunterMakesPy.egg-info/PKG-INFO +1 -1
- {huntermakespy-0.7.2 → huntermakespy-0.7.3}/pyproject.toml +1 -1
- {huntermakespy-0.7.2 → huntermakespy-0.7.3}/LICENSE +0 -0
- {huntermakespy-0.7.2 → huntermakespy-0.7.3}/README.md +0 -0
- {huntermakespy-0.7.2 → huntermakespy-0.7.3}/hunterMakesPy/__init__.py +0 -0
- {huntermakespy-0.7.2 → huntermakespy-0.7.3}/hunterMakesPy/_theSSOT.py +0 -0
- {huntermakespy-0.7.2 → huntermakespy-0.7.3}/hunterMakesPy/coping.py +0 -0
- {huntermakespy-0.7.2 → huntermakespy-0.7.3}/hunterMakesPy/dataStructures.py +0 -0
- {huntermakespy-0.7.2 → huntermakespy-0.7.3}/hunterMakesPy/filesystemToolkit.py +0 -0
- {huntermakespy-0.7.2 → huntermakespy-0.7.3}/hunterMakesPy/py.typed +0 -0
- {huntermakespy-0.7.2 → huntermakespy-0.7.3}/hunterMakesPy/semiotics.py +0 -0
- {huntermakespy-0.7.2 → huntermakespy-0.7.3}/hunterMakesPy/tests/__init__.py +0 -0
- {huntermakespy-0.7.2 → huntermakespy-0.7.3}/hunterMakesPy/tests/conftest.py +0 -0
- {huntermakespy-0.7.2 → huntermakespy-0.7.3}/hunterMakesPy/tests/test_coping.py +0 -0
- {huntermakespy-0.7.2 → huntermakespy-0.7.3}/hunterMakesPy/tests/test_dataStructures.py +0 -0
- {huntermakespy-0.7.2 → huntermakespy-0.7.3}/hunterMakesPy/tests/test_filesystemToolkit.py +0 -0
- {huntermakespy-0.7.2 → huntermakespy-0.7.3}/hunterMakesPy/tests/test_parseParameters.py +0 -0
- {huntermakespy-0.7.2 → huntermakespy-0.7.3}/hunterMakesPy/tests/test_theTypes.py +0 -0
- {huntermakespy-0.7.2 → huntermakespy-0.7.3}/hunterMakesPy/theTypesCallableFunction.py +0 -0
- {huntermakespy-0.7.2 → huntermakespy-0.7.3}/hunterMakesPy.egg-info/SOURCES.txt +0 -0
- {huntermakespy-0.7.2 → huntermakespy-0.7.3}/hunterMakesPy.egg-info/dependency_links.txt +0 -0
- {huntermakespy-0.7.2 → huntermakespy-0.7.3}/hunterMakesPy.egg-info/requires.txt +0 -0
- {huntermakespy-0.7.2 → huntermakespy-0.7.3}/hunterMakesPy.egg-info/top_level.txt +0 -0
- {huntermakespy-0.7.2 → huntermakespy-0.7.3}/setup.cfg +0 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# ruff: noqa: TRY301, DOC501, PLW0717 BLE001
|
|
1
2
|
"""Validate parameters and parse input with defensive error handling.
|
|
2
3
|
|
|
3
4
|
(AI generated docstring)
|
|
@@ -35,7 +36,7 @@ References
|
|
|
35
36
|
"""
|
|
36
37
|
from __future__ import annotations
|
|
37
38
|
|
|
38
|
-
from collections.abc import
|
|
39
|
+
from collections.abc import Sized
|
|
39
40
|
from dataclasses import dataclass
|
|
40
41
|
from typing import TYPE_CHECKING
|
|
41
42
|
import charset_normalizer
|
|
@@ -44,6 +45,8 @@ import sys
|
|
|
44
45
|
|
|
45
46
|
if TYPE_CHECKING:
|
|
46
47
|
from charset_normalizer.models import CharsetMatch
|
|
48
|
+
from collections.abc import Iterable
|
|
49
|
+
from hunterMakesPy.theTypes import Limitation
|
|
47
50
|
from typing import Any
|
|
48
51
|
|
|
49
52
|
@dataclass
|
|
@@ -68,60 +71,9 @@ class ErrorMessageContext:
|
|
|
68
71
|
containerType: str | None = None
|
|
69
72
|
isElement: bool = False
|
|
70
73
|
|
|
71
|
-
def
|
|
72
|
-
"""Construct error message from available context using template.
|
|
73
|
-
|
|
74
|
-
I received ["value" | a value | `None`] [of type `type` | `None`] [as an element in | `None`] [a `containerType` type |
|
|
75
|
-
`None`] but `parameterName` must have integers [in type(s) `parameterType` | `None`].
|
|
76
|
-
|
|
77
|
-
Hypothetically, this is a prototype that can be generalized to other functions. In this package and a few of my other
|
|
78
|
-
packages, I have developed standardized error messages, but those are quite different from this. I will certainly continue to
|
|
79
|
-
develop this kind of functionality, and this function will influence things.
|
|
80
|
-
|
|
81
|
-
Parameters
|
|
82
|
-
----------
|
|
83
|
-
context : ErrorMessageContext
|
|
84
|
-
The error context containing parameter value, type, and container information.
|
|
85
|
-
parameterName : str
|
|
86
|
-
The name of the parameter that caused the error.
|
|
87
|
-
parameterType : type[Any] | None
|
|
88
|
-
The expected type of the parameter, used in error messages.
|
|
89
|
-
|
|
90
|
-
Returns
|
|
91
|
-
-------
|
|
92
|
-
errorMessage : str
|
|
93
|
-
The constructed error message string.
|
|
94
|
-
|
|
95
|
-
"""
|
|
96
|
-
messageParts: list[str] = ["I received "]
|
|
97
|
-
|
|
98
|
-
if context.parameterValue is not None and not isinstance(context.parameterValue, (bytes, bytearray, memoryview)):
|
|
99
|
-
messageParts.append(f'"{context.parameterValue}"')
|
|
100
|
-
else:
|
|
101
|
-
messageParts.append("a value")
|
|
102
|
-
|
|
103
|
-
if context.parameterValueType:
|
|
104
|
-
messageParts.append(f" of type `{context.parameterValueType}`")
|
|
105
|
-
|
|
106
|
-
if context.isElement:
|
|
107
|
-
messageParts.append(" as an element in")
|
|
108
|
-
|
|
109
|
-
if context.containerType:
|
|
110
|
-
messageParts.append(f" a `{context.containerType}` type")
|
|
111
|
-
|
|
112
|
-
messageParts.append(f" but {parameterName} must have integers")
|
|
113
|
-
|
|
114
|
-
if parameterType:
|
|
115
|
-
messageParts.append(f" in type(s) `{parameterType}`")
|
|
116
|
-
|
|
117
|
-
return "".join(messageParts)
|
|
118
|
-
|
|
119
|
-
def defineConcurrencyLimit(*, limit: bool | float | int | None, cpuTotal: int = multiprocessing.cpu_count()) -> int:
|
|
74
|
+
def defineConcurrencyLimit(*, limit: Limitation, cpuTotal: int = multiprocessing.cpu_count()) -> int:
|
|
120
75
|
"""Determine the concurrency limit based on the provided parameter.
|
|
121
76
|
|
|
122
|
-
Tests for this function can be run with:
|
|
123
|
-
`from hunterMakesPy.tests.test_parseParameters import PytestFor_defineConcurrencyLimit`
|
|
124
|
-
|
|
125
77
|
Parameters
|
|
126
78
|
----------
|
|
127
79
|
limit : bool | float | int | None
|
|
@@ -134,20 +86,11 @@ def defineConcurrencyLimit(*, limit: bool | float | int | None, cpuTotal: int =
|
|
|
134
86
|
concurrencyLimit : int
|
|
135
87
|
The calculated concurrency limit, ensuring it is at least 1.
|
|
136
88
|
|
|
137
|
-
Notes
|
|
138
|
-
-----
|
|
139
|
-
Consider using `hunterMakesPy.oopsieKwargsie()` to handle malformed inputs. For example:
|
|
140
|
-
|
|
141
|
-
```
|
|
142
|
-
if not (CPUlimit is None or isinstance(CPUlimit, (bool, int, float))):
|
|
143
|
-
CPUlimit = oopsieKwargsie(CPUlimit)
|
|
144
|
-
```
|
|
145
|
-
|
|
146
89
|
Example parameters
|
|
147
90
|
------------------
|
|
148
91
|
```python
|
|
149
92
|
CPUlimit: bool | float | int | None
|
|
150
|
-
CPUlimit:
|
|
93
|
+
CPUlimit: Limitation = None
|
|
151
94
|
```
|
|
152
95
|
|
|
153
96
|
Example docstring
|
|
@@ -171,7 +114,7 @@ def defineConcurrencyLimit(*, limit: bool | float | int | None, cpuTotal: int =
|
|
|
171
114
|
- If the value of `CPUlimit` is a `float` greater than 1 or less than -1, the function truncates the value to an `int` with the same sign as the `float`.
|
|
172
115
|
```
|
|
173
116
|
|
|
174
|
-
"""
|
|
117
|
+
"""
|
|
175
118
|
if isinstance(limit, str):
|
|
176
119
|
limitFromString: bool | str | None = oopsieKwargsie(limit)
|
|
177
120
|
if isinstance(limitFromString, str):
|
|
@@ -204,7 +147,53 @@ def defineConcurrencyLimit(*, limit: bool | float | int | None, cpuTotal: int =
|
|
|
204
147
|
concurrencyLimit = min(concurrencyLimit, 61)
|
|
205
148
|
return max(int(concurrencyLimit), 1)
|
|
206
149
|
|
|
207
|
-
|
|
150
|
+
def _constructErrorMessage(context: ErrorMessageContext, parameterName: str, parameterType: type[Any] | None) -> str:
|
|
151
|
+
"""Construct error message from available context using template.
|
|
152
|
+
|
|
153
|
+
I received ["value" | a value | `None`] [of type `type` | `None`] [as an element in | `None`] [a `containerType` type |
|
|
154
|
+
`None`] but `parameterName` must have integers [in type(s) `parameterType` | `None`].
|
|
155
|
+
|
|
156
|
+
Hypothetically, this is a prototype that can be generalized to other functions. In this package and a few of my other
|
|
157
|
+
packages, I have developed standardized error messages, but those are quite different from this. I will certainly continue to
|
|
158
|
+
develop this kind of functionality, and this function will influence things.
|
|
159
|
+
|
|
160
|
+
Parameters
|
|
161
|
+
----------
|
|
162
|
+
context : ErrorMessageContext
|
|
163
|
+
The error context containing parameter value, type, and container information.
|
|
164
|
+
parameterName : str
|
|
165
|
+
The name of the parameter that caused the error.
|
|
166
|
+
parameterType : type[Any] | None
|
|
167
|
+
The expected type of the parameter, used in error messages.
|
|
168
|
+
|
|
169
|
+
Returns
|
|
170
|
+
-------
|
|
171
|
+
errorMessage : str
|
|
172
|
+
The constructed error message string.
|
|
173
|
+
|
|
174
|
+
"""
|
|
175
|
+
messageParts: list[str] = ["I received "]
|
|
176
|
+
|
|
177
|
+
if context.parameterValue is not None and not isinstance(context.parameterValue, (bytes, bytearray, memoryview)):
|
|
178
|
+
messageParts.append(f'"{context.parameterValue}"')
|
|
179
|
+
else:
|
|
180
|
+
messageParts.append("a value")
|
|
181
|
+
|
|
182
|
+
if context.parameterValueType:
|
|
183
|
+
messageParts.append(f" of type `{context.parameterValueType}`")
|
|
184
|
+
|
|
185
|
+
if context.isElement:
|
|
186
|
+
messageParts.append(" as an element in")
|
|
187
|
+
|
|
188
|
+
if context.containerType:
|
|
189
|
+
messageParts.append(f" a `{context.containerType}` type")
|
|
190
|
+
|
|
191
|
+
messageParts.append(f" but {parameterName} must have integers")
|
|
192
|
+
|
|
193
|
+
if parameterType:
|
|
194
|
+
messageParts.append(f" in type(s) `{parameterType}`")
|
|
195
|
+
|
|
196
|
+
return "".join(messageParts)
|
|
208
197
|
|
|
209
198
|
def intInnit(listInt_Allegedly: Iterable[Any], parameterName: str | None = None, parameterType: type[Any] | None = None) -> list[int]:
|
|
210
199
|
"""Validate and convert input values to a `list` of integers.
|
|
@@ -252,7 +241,7 @@ def intInnit(listInt_Allegedly: Iterable[Any], parameterName: str | None = None,
|
|
|
252
241
|
|
|
253
242
|
# Be nice, and assume the input container is valid and every element is valid.
|
|
254
243
|
# Nevertheless, this is a "fail-early" step, so reject ambiguity and try to induce errors now that could be catastrophic later.
|
|
255
|
-
try:
|
|
244
|
+
try:
|
|
256
245
|
iter(listInt_Allegedly)
|
|
257
246
|
lengthInitial: int | None = None
|
|
258
247
|
if isinstance(listInt_Allegedly, Sized):
|
|
@@ -349,7 +338,7 @@ def oopsieKwargsie(huh: Any) -> bool | str | None:
|
|
|
349
338
|
if not isinstance(huh, str):
|
|
350
339
|
try:
|
|
351
340
|
huh = str(huh)
|
|
352
|
-
except BaseException:
|
|
341
|
+
except BaseException:
|
|
353
342
|
return huh
|
|
354
343
|
formatted: str = huh.strip().title()
|
|
355
344
|
if formatted == str(True):
|
|
@@ -11,6 +11,8 @@ identifierDotAttribute: TypeAlias = str
|
|
|
11
11
|
`TypeAlias` for a `str` `object` using dot notation to access an attribute, such as 'scipy.signal.windows'.
|
|
12
12
|
"""
|
|
13
13
|
|
|
14
|
+
Limitation: TypeAlias = bool | float | int | None
|
|
15
|
+
|
|
14
16
|
class Ordinals(Protocol):
|
|
15
17
|
"""Any Python `object` `type` that may be ordered before or after a comparable `object` `type` by comparison operators."""
|
|
16
18
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|