hunterMakesPy 0.9.0__tar.gz → 0.10.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.
- {huntermakespy-0.9.0 → huntermakespy-0.10.0}/PKG-INFO +12 -13
- {huntermakespy-0.9.0 → huntermakespy-0.10.0}/README.md +7 -8
- {huntermakespy-0.9.0 → huntermakespy-0.10.0}/hunterMakesPy/__init__.py +22 -7
- {huntermakespy-0.9.0 → huntermakespy-0.10.0}/hunterMakesPy/coping.py +22 -22
- {huntermakespy-0.9.0 → huntermakespy-0.10.0}/hunterMakesPy/dataStructures.py +98 -45
- huntermakespy-0.9.0/hunterMakesPy/filesystemToolkit.py → huntermakespy-0.10.0/hunterMakesPy/kitFilesystem.py +152 -59
- huntermakespy-0.10.0/hunterMakesPy/parseParameters.py +276 -0
- huntermakespy-0.10.0/hunterMakesPy/tests/__init__.py +31 -0
- huntermakespy-0.10.0/hunterMakesPy/tests/conftest.py +24 -0
- huntermakespy-0.10.0/hunterMakesPy/tests/conftestAnnex.py +45 -0
- huntermakespy-0.10.0/hunterMakesPy/tests/test_coping.py +52 -0
- huntermakespy-0.10.0/hunterMakesPy/tests/test_dataStructures.py +79 -0
- huntermakespy-0.10.0/hunterMakesPy/tests/test_kitFilesystem.py +83 -0
- huntermakespy-0.10.0/hunterMakesPy/tests/test_parseParameters.py +53 -0
- huntermakespy-0.10.0/hunterMakesPy/tests/test_theTypes.py +15 -0
- huntermakespy-0.10.0/hunterMakesPy/theTypes.py +180 -0
- {huntermakespy-0.9.0 → huntermakespy-0.10.0}/hunterMakesPy.egg-info/PKG-INFO +12 -13
- {huntermakespy-0.9.0 → huntermakespy-0.10.0}/hunterMakesPy.egg-info/SOURCES.txt +2 -3
- {huntermakespy-0.9.0 → huntermakespy-0.10.0}/hunterMakesPy.egg-info/requires.txt +4 -4
- {huntermakespy-0.9.0 → huntermakespy-0.10.0}/pyproject.toml +8 -5
- huntermakespy-0.9.0/hunterMakesPy/parseParameters.py +0 -351
- huntermakespy-0.9.0/hunterMakesPy/tests/__init__.py +0 -33
- huntermakespy-0.9.0/hunterMakesPy/tests/conftest.py +0 -145
- huntermakespy-0.9.0/hunterMakesPy/tests/conftestAnnex.py +0 -22
- huntermakespy-0.9.0/hunterMakesPy/tests/test_coping.py +0 -322
- huntermakespy-0.9.0/hunterMakesPy/tests/test_dataStructures.py +0 -190
- huntermakespy-0.9.0/hunterMakesPy/tests/test_filesystemToolkit.py +0 -564
- huntermakespy-0.9.0/hunterMakesPy/tests/test_parseParameters.py +0 -402
- huntermakespy-0.9.0/hunterMakesPy/tests/test_theTypes.py +0 -246
- huntermakespy-0.9.0/hunterMakesPy/theTypes.py +0 -29
- huntermakespy-0.9.0/hunterMakesPy/theTypesCallableFunction.py +0 -63
- {huntermakespy-0.9.0 → huntermakespy-0.10.0}/LICENSE +0 -0
- {huntermakespy-0.9.0 → huntermakespy-0.10.0}/hunterMakesPy/_theSSOT.py +0 -0
- {huntermakespy-0.9.0 → huntermakespy-0.10.0}/hunterMakesPy/py.typed +0 -0
- {huntermakespy-0.9.0 → huntermakespy-0.10.0}/hunterMakesPy/semiotics.py +0 -0
- {huntermakespy-0.9.0 → huntermakespy-0.10.0}/hunterMakesPy.egg-info/dependency_links.txt +0 -0
- {huntermakespy-0.9.0 → huntermakespy-0.10.0}/hunterMakesPy.egg-info/top_level.txt +0 -0
- {huntermakespy-0.9.0 → huntermakespy-0.10.0}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: hunterMakesPy
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.10.0
|
|
4
4
|
Summary: Easy Python functions making making functional Python functions easier.
|
|
5
5
|
Author-email: Hunter Hogan <HunterHogan@pm.me>
|
|
6
6
|
License-Expression: CC-BY-NC-4.0
|
|
@@ -30,14 +30,14 @@ Requires-Dist: autoflake
|
|
|
30
30
|
Requires-Dist: charset_normalizer
|
|
31
31
|
Requires-Dist: isort
|
|
32
32
|
Requires-Dist: more_itertools
|
|
33
|
-
Requires-Dist: numpy
|
|
34
|
-
Requires-Dist: tomli
|
|
33
|
+
Requires-Dist: numpy>=2.0
|
|
35
34
|
Requires-Dist: typing_extensions>=4.10.0
|
|
36
35
|
Provides-Extra: development
|
|
37
36
|
Requires-Dist: pytest-cov; extra == "development"
|
|
38
37
|
Provides-Extra: testing
|
|
39
|
-
Requires-Dist:
|
|
40
|
-
Requires-Dist: pytest; extra == "testing"
|
|
38
|
+
Requires-Dist: hypothesis; extra == "testing"
|
|
39
|
+
Requires-Dist: pytest>=9.0; extra == "testing"
|
|
40
|
+
Requires-Dist: pytest-xdist; extra == "testing"
|
|
41
41
|
Dynamic: license-file
|
|
42
42
|
|
|
43
43
|
# hunterMakesPy
|
|
@@ -108,9 +108,10 @@ step = decreasing
|
|
|
108
108
|
Load functions or classes from `"scipy.signal.windows"` or `"path/to/file.py"` without manual module-loading boilerplate.
|
|
109
109
|
|
|
110
110
|
```python
|
|
111
|
-
from hunterMakesPy.
|
|
111
|
+
from hunterMakesPy.kitFilesystem import importLogicalPath2Identifier, importPathFilename2Identifier
|
|
112
112
|
|
|
113
113
|
windowFunction = importLogicalPath2Identifier("scipy.signal.windows", "hann")
|
|
114
|
+
parse = importPathFilename2Identifier("path/to/asdl.py", "parse")
|
|
114
115
|
```
|
|
115
116
|
|
|
116
117
|
## Create Directories Safely and Write Files with Formatting
|
|
@@ -118,7 +119,7 @@ windowFunction = importLogicalPath2Identifier("scipy.signal.windows", "hann")
|
|
|
118
119
|
Write to `"deep/nested/path/file.txt"` and parent directories are created automatically. `writePython` removes unused imports and sorts import statements before writing.
|
|
119
120
|
|
|
120
121
|
```python
|
|
121
|
-
from hunterMakesPy.
|
|
122
|
+
from hunterMakesPy.kitFilesystem import writeStringToHere, writePython
|
|
122
123
|
|
|
123
124
|
writeStringToHere("content", "nested/dirs/file.txt") # Creates dirs
|
|
124
125
|
writePython(sourceCode, "output/module.py") # Formats, then writes
|
|
@@ -170,16 +171,14 @@ from hunterMakesPy import PackageSettings
|
|
|
170
171
|
settings = PackageSettings(identifierPackageFALLBACK="myPackage")
|
|
171
172
|
```
|
|
172
173
|
|
|
173
|
-
##
|
|
174
|
+
## Report the Call That Broke a Test
|
|
174
175
|
|
|
175
|
-
Import parameterized test
|
|
176
|
+
Import assertion functions that name the function and the arguments in the failure message, so a failing parameterized test shows exactly which call produced the wrong value. `assert_array_equal` and `assert_allclose` do the same for NumPy arrays.
|
|
176
177
|
|
|
177
178
|
```python
|
|
178
|
-
from hunterMakesPy.tests
|
|
179
|
+
from hunterMakesPy.tests import assertEqualTo
|
|
179
180
|
|
|
180
|
-
|
|
181
|
-
def test_my_integer_validator(test_name, test_func):
|
|
182
|
-
test_func()
|
|
181
|
+
assertEqualTo(intInnit(["8080", 443]), [8080, 443], intInnit.__name__, ["8080", 443])
|
|
183
182
|
```
|
|
184
183
|
|
|
185
184
|
## My recovery
|
|
@@ -66,9 +66,10 @@ step = decreasing
|
|
|
66
66
|
Load functions or classes from `"scipy.signal.windows"` or `"path/to/file.py"` without manual module-loading boilerplate.
|
|
67
67
|
|
|
68
68
|
```python
|
|
69
|
-
from hunterMakesPy.
|
|
69
|
+
from hunterMakesPy.kitFilesystem import importLogicalPath2Identifier, importPathFilename2Identifier
|
|
70
70
|
|
|
71
71
|
windowFunction = importLogicalPath2Identifier("scipy.signal.windows", "hann")
|
|
72
|
+
parse = importPathFilename2Identifier("path/to/asdl.py", "parse")
|
|
72
73
|
```
|
|
73
74
|
|
|
74
75
|
## Create Directories Safely and Write Files with Formatting
|
|
@@ -76,7 +77,7 @@ windowFunction = importLogicalPath2Identifier("scipy.signal.windows", "hann")
|
|
|
76
77
|
Write to `"deep/nested/path/file.txt"` and parent directories are created automatically. `writePython` removes unused imports and sorts import statements before writing.
|
|
77
78
|
|
|
78
79
|
```python
|
|
79
|
-
from hunterMakesPy.
|
|
80
|
+
from hunterMakesPy.kitFilesystem import writeStringToHere, writePython
|
|
80
81
|
|
|
81
82
|
writeStringToHere("content", "nested/dirs/file.txt") # Creates dirs
|
|
82
83
|
writePython(sourceCode, "output/module.py") # Formats, then writes
|
|
@@ -128,16 +129,14 @@ from hunterMakesPy import PackageSettings
|
|
|
128
129
|
settings = PackageSettings(identifierPackageFALLBACK="myPackage")
|
|
129
130
|
```
|
|
130
131
|
|
|
131
|
-
##
|
|
132
|
+
## Report the Call That Broke a Test
|
|
132
133
|
|
|
133
|
-
Import parameterized test
|
|
134
|
+
Import assertion functions that name the function and the arguments in the failure message, so a failing parameterized test shows exactly which call produced the wrong value. `assert_array_equal` and `assert_allclose` do the same for NumPy arrays.
|
|
134
135
|
|
|
135
136
|
```python
|
|
136
|
-
from hunterMakesPy.tests
|
|
137
|
+
from hunterMakesPy.tests import assertEqualTo
|
|
137
138
|
|
|
138
|
-
|
|
139
|
-
def test_my_integer_validator(test_name, test_func):
|
|
140
|
-
test_func()
|
|
139
|
+
assertEqualTo(intInnit(["8080", 443]), [8080, 443], intInnit.__name__, ["8080", 443])
|
|
141
140
|
```
|
|
142
141
|
|
|
143
142
|
## My recovery
|
|
@@ -8,8 +8,7 @@ data structures with specialized encoding and merging utilities. The package pro
|
|
|
8
8
|
curated collection of functions for common programming tasks with emphasis on fail-early
|
|
9
9
|
validation and explicit semantic intent.
|
|
10
10
|
|
|
11
|
-
The package re-exports
|
|
12
|
-
`zeroIndexed`) and type definitions (`identifierDotAttribute`, `Ordinals`) for direct
|
|
11
|
+
The package re-exports semantic constants, ANSI color codes, and type definitions for direct
|
|
13
12
|
access. The package exposes configuration utilities (`PackageSettings`) and defensive
|
|
14
13
|
programming functions (`raiseIfNone`) as primary interfaces. Public modules provide
|
|
15
14
|
specialized functionality for parameter parsing, file operations, and data structure
|
|
@@ -24,14 +23,32 @@ Semantic Constants
|
|
|
24
23
|
Signal an error state with a visually distinctive numeric value.
|
|
25
24
|
inclusive
|
|
26
25
|
Express inclusion or exclusion of a boundary value.
|
|
26
|
+
oneIndexed
|
|
27
|
+
Express that the adjustment to a value is due to one-based indexing.
|
|
27
28
|
zeroIndexed
|
|
28
29
|
Express that the adjustment to a value is due to zero-based indexing.
|
|
29
30
|
|
|
31
|
+
Terminal Colors
|
|
32
|
+
ansiColor
|
|
33
|
+
Look up ANSI escape codes for terminal text and background colors.
|
|
34
|
+
ansiColorReset
|
|
35
|
+
Reset terminal text color and background to default settings.
|
|
36
|
+
|
|
30
37
|
Type Definitions
|
|
38
|
+
CallableFunction
|
|
39
|
+
Annotate a function in place of `Callable` so that type checkers accept `__name__`.
|
|
40
|
+
ConcurrencyLimit
|
|
41
|
+
Type alias for the values that specify a number of concurrent workers.
|
|
31
42
|
identifierDotAttribute
|
|
32
43
|
String representing a dotted attribute identifier.
|
|
33
44
|
Ordinals
|
|
34
45
|
Protocol for types supporting comparison operators.
|
|
46
|
+
小于
|
|
47
|
+
Type variable bound to `Ordinals`.
|
|
48
|
+
文义
|
|
49
|
+
Unbounded type variable.
|
|
50
|
+
文件
|
|
51
|
+
Type variable bound to `Hashable`.
|
|
35
52
|
|
|
36
53
|
Configuration and Defensive Programming
|
|
37
54
|
PackageSettings
|
|
@@ -45,18 +62,16 @@ coping
|
|
|
45
62
|
Package configuration and defensive programming utilities.
|
|
46
63
|
dataStructures
|
|
47
64
|
Data structure manipulation with encoding, extraction, and merging utilities.
|
|
48
|
-
|
|
65
|
+
kitFilesystem
|
|
49
66
|
File system operations and dynamic module imports.
|
|
50
67
|
parseParameters
|
|
51
68
|
Parameter validation, integer parsing, and concurrency limit computation.
|
|
52
|
-
pytestForYourUse
|
|
53
|
-
Backward compatibility module redirecting to test_parseParameters.
|
|
54
69
|
semiotics
|
|
55
70
|
Semantic constants and ANSI color codes for terminal output.
|
|
71
|
+
tests
|
|
72
|
+
Test suites for the package modules, and assertion functions that other packages can import.
|
|
56
73
|
theTypes
|
|
57
74
|
Type aliases and protocols for type annotations.
|
|
58
|
-
tests
|
|
59
|
-
Comprehensive test suites for all package modules.
|
|
60
75
|
|
|
61
76
|
References
|
|
62
77
|
----------
|
|
@@ -3,49 +3,52 @@ from __future__ import annotations
|
|
|
3
3
|
|
|
4
4
|
from importlib.util import find_spec
|
|
5
5
|
from pathlib import Path
|
|
6
|
-
from tomli import loads as tomli_loads
|
|
7
6
|
from typing import TYPE_CHECKING
|
|
8
|
-
|
|
7
|
+
import contextlib
|
|
9
8
|
import dataclasses
|
|
9
|
+
import tomllib
|
|
10
10
|
|
|
11
11
|
if TYPE_CHECKING:
|
|
12
12
|
from importlib.machinery import ModuleSpec
|
|
13
13
|
|
|
14
14
|
def getIdentifierPackagePACKAGING(identifierPackageFALLBACK: str) -> str:
|
|
15
15
|
"""Get package name from pyproject.toml or fallback to provided value."""
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return identifierPackageFALLBACK
|
|
16
|
+
identifierPackage: str = identifierPackageFALLBACK
|
|
17
|
+
with contextlib.suppress(OSError, tomllib.TOMLDecodeError, KeyError):
|
|
18
|
+
identifierPackage = tomllib.loads(Path('pyproject.toml').read_text(encoding='utf-8'))['project']['name'] or identifierPackageFALLBACK
|
|
19
|
+
return identifierPackage
|
|
21
20
|
|
|
22
21
|
def getPathPackageINSTALLING(identifierPackage: str) -> Path:
|
|
23
22
|
"""Return the root directory of the installed package."""
|
|
24
|
-
|
|
23
|
+
pathPackage: Path = Path.cwd()
|
|
24
|
+
with contextlib.suppress(ModuleNotFoundError):
|
|
25
25
|
moduleSpecification: ModuleSpec | None = find_spec(identifierPackage)
|
|
26
26
|
if moduleSpecification and moduleSpecification.origin:
|
|
27
27
|
pathFilename: Path = Path(moduleSpecification.origin)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
if pathFilename.is_file():
|
|
29
|
+
pathPackage = pathFilename.parent
|
|
30
|
+
else:
|
|
31
|
+
pathPackage = pathFilename
|
|
32
|
+
return pathPackage
|
|
32
33
|
|
|
33
34
|
@dataclasses.dataclass
|
|
34
35
|
class PackageSettings:
|
|
35
36
|
"""Configuration container for Python package metadata and runtime settings.
|
|
36
37
|
|
|
37
|
-
This `class` provides a simple way to store and access basic information about a Python package,
|
|
38
|
-
package identifiers and installation paths if they are not passed to
|
|
39
|
-
subtype and extend.
|
|
38
|
+
This `class` provides a simple way to store and access basic information about a Python package,
|
|
39
|
+
It will automatically resolve package identifiers and installation paths if they are not passed to
|
|
40
|
+
the `class` constructor. Python `dataclasses` are easy to subtype and extend.
|
|
40
41
|
|
|
41
42
|
Attributes
|
|
42
43
|
----------
|
|
43
44
|
identifierPackageFALLBACK : str = ''
|
|
44
45
|
Fallback package identifier used only during initialization when automatic discovery fails.
|
|
45
46
|
identifierPackage : str = ''
|
|
46
|
-
Canonical name of the package.
|
|
47
|
+
Canonical name of the package. An explicit value takes precedence over `pyproject.toml`, then
|
|
48
|
+
`identifierPackageFALLBACK`.
|
|
47
49
|
pathPackage : Path = getPathPackageINSTALLING(identifierPackage)
|
|
48
|
-
Absolute path to the installed package directory. Automatically resolved from
|
|
50
|
+
Absolute path to the installed package directory. Automatically resolved from
|
|
51
|
+
`identifierPackage` if not provided.
|
|
49
52
|
fileExtension : str = '.py'
|
|
50
53
|
Default file extension.
|
|
51
54
|
|
|
@@ -79,14 +82,11 @@ class PackageSettings:
|
|
|
79
82
|
|
|
80
83
|
def __post_init__(self, identifierPackageFALLBACK: str) -> None:
|
|
81
84
|
"""Initialize computed fields after dataclass initialization."""
|
|
82
|
-
|
|
83
|
-
self.identifierPackage = getIdentifierPackagePACKAGING(identifierPackageFALLBACK)
|
|
85
|
+
self.identifierPackage = self.identifierPackage or getIdentifierPackagePACKAGING(identifierPackageFALLBACK)
|
|
84
86
|
if self.pathPackage == Path() and self.identifierPackage:
|
|
85
87
|
self.pathPackage = getPathPackageINSTALLING(self.identifierPackage)
|
|
86
88
|
|
|
87
|
-
TypeSansNone =
|
|
88
|
-
|
|
89
|
-
def raiseIfNone(expression: TypeSansNone | None, errorMessage: str | None = None) -> TypeSansNone:
|
|
89
|
+
def raiseIfNone[TypeSansNone](expression: TypeSansNone | None, errorMessage: str | None = None) -> TypeSansNone:
|
|
90
90
|
"""Convert the `expression` return annotation from '`cerPytainty | None`' to '`cerPytainty`' because `expression` cannot be `None`; `raise` an `Exception` if you're wrong.
|
|
91
91
|
|
|
92
92
|
The Python interpreter evaluates `expression` to a value: think of a function call or an attribute access. You can use
|
|
@@ -12,7 +12,7 @@ Functions
|
|
|
12
12
|
removeExtraWhitespace
|
|
13
13
|
Remove whitespace after commas and inside parentheses or square brackets.
|
|
14
14
|
stringItUp
|
|
15
|
-
|
|
15
|
+
Collect string representations from nested values.
|
|
16
16
|
updateExtendPolishDictionaryLists
|
|
17
17
|
Merge iterable values into lists with optional deduplication and sorting.
|
|
18
18
|
"""
|
|
@@ -36,42 +36,65 @@ if TYPE_CHECKING:
|
|
|
36
36
|
from typing import Any, Literal
|
|
37
37
|
|
|
38
38
|
def removeExtraWhitespace(string: str) -> str:
|
|
39
|
-
"""Remove
|
|
39
|
+
"""Remove whitespace after commas and inside parentheses or square brackets.
|
|
40
|
+
|
|
41
|
+
(AI generated docstring)
|
|
42
|
+
|
|
43
|
+
Parameters
|
|
44
|
+
----------
|
|
45
|
+
string : str
|
|
46
|
+
Text to compact. Whitespace inside quoted text is affected too, so use this operation
|
|
47
|
+
only when that whitespace can be removed without changing the intended meaning.
|
|
48
|
+
|
|
49
|
+
Returns
|
|
50
|
+
-------
|
|
51
|
+
stringCompacted : str
|
|
52
|
+
Text without whitespace immediately after commas, opening parentheses, or opening
|
|
53
|
+
square brackets, or immediately before closing parentheses or closing square brackets.
|
|
54
|
+
"""
|
|
40
55
|
commas: str = regex.sub(r',\s+', ',', string)
|
|
41
56
|
bracketsOpening: str = regex.sub(r'([\[\(])\s+', r'\1', commas)
|
|
42
57
|
return regex.sub(r'\s+([\]\)])', r'\1', bracketsOpening)
|
|
43
58
|
|
|
44
59
|
def autoDecodingRLE(arrayTarget: NDArray[integer[Any]], *, assumeAddSpaces: bool = False) -> str:
|
|
45
|
-
"""Transform a NumPy array into a compact, self-decoding
|
|
60
|
+
"""Transform a NumPy integer array into a compact, self-decoding Python expression.
|
|
61
|
+
|
|
62
|
+
(AI generated docstring)
|
|
46
63
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
sequences. 2. Multiplication syntax for repeated elements.
|
|
64
|
+
You can convert a NumPy integer array into text that, when evaluated as Python code, reproduces
|
|
65
|
+
`arrayTarget.tolist()`. You can create a NumPy array, a PyTorch tensor, or another array-like
|
|
66
|
+
object from the decoded value. The RLE (Run-Length Encoding) text does not need a decoder
|
|
67
|
+
function; it is native Python syntax using unpacked `range` expressions for consecutive integers
|
|
68
|
+
and list multiplication for repeated elements.
|
|
53
69
|
|
|
54
|
-
The resulting
|
|
55
|
-
|
|
70
|
+
The resulting text is minified Python code, so it is space-efficient and, hypothetically,
|
|
71
|
+
human-readable.
|
|
56
72
|
|
|
57
73
|
Parameters
|
|
58
74
|
----------
|
|
59
75
|
arrayTarget : NDArray[integer[Any]]
|
|
60
|
-
The NumPy array to
|
|
76
|
+
The NumPy integer array to encode. A zero-dimensional array produces a scalar expression;
|
|
77
|
+
all other arrays produce a list expression.
|
|
61
78
|
assumeAddSpaces : bool = False
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
79
|
+
Whether encoding choices should account for spaces that `ast.unparse` or a Python
|
|
80
|
+
formatter may insert. `True` estimates one space per comma and two spaces around
|
|
81
|
+
multiplication after `]`. The returned expression remains compact in either mode.
|
|
65
82
|
|
|
66
83
|
Returns
|
|
67
84
|
-------
|
|
68
85
|
encodedString : str
|
|
69
|
-
A
|
|
70
|
-
|
|
86
|
+
A Python expression representing `arrayTarget.tolist()`. The expression does not store
|
|
87
|
+
NumPy dtype or shape metadata, including dimensions beyond an empty axis.
|
|
71
88
|
"""
|
|
72
89
|
def sliceNDArrayToNestedLists(arraySlice: NDArray[integer[Any]]) -> Any:
|
|
73
90
|
def getLengthOption(optionAsStr: str) -> int:
|
|
74
|
-
"""
|
|
91
|
+
"""I use this estimate to compare encoding lengths with optional formatter spaces.
|
|
92
|
+
|
|
93
|
+
(AI generated docstring)
|
|
94
|
+
|
|
95
|
+
The estimate includes one extra space per comma and two extra spaces per `]*` when
|
|
96
|
+
`assumeAddSpaces` is `True`.
|
|
97
|
+
"""
|
|
75
98
|
return assumeAddSpaces * (optionAsStr.count(',') + optionAsStr.count(']*') * 2) + len(optionAsStr)
|
|
76
99
|
|
|
77
100
|
if 1 < arraySlice.ndim:
|
|
@@ -148,18 +171,24 @@ def autoDecodingRLE(arrayTarget: NDArray[integer[Any]], *, assumeAddSpaces: bool
|
|
|
148
171
|
patternRegex: regex.Pattern[str] = regex.compile(
|
|
149
172
|
r"(?<!rang)(?:"
|
|
150
173
|
#Pattern 1: Comma ahead, bracket behind
|
|
151
|
-
r"(?P<joinAhead>,)\((?P<malkovich
|
|
174
|
+
r"(?P<joinAhead>,)\((?P<malkovich>-?\d+|range\(-?\d+,-?\d+\)),(?P<multiply>\d+)\)(?P<bracketBehind>])|"
|
|
152
175
|
#Pattern 2: Bracket or start ahead, comma behind
|
|
153
|
-
r"(?P<bracketOrStartAhead>\[|^.)\((?P<malkovichMalkovich
|
|
176
|
+
r"(?P<bracketOrStartAhead>\[|^.)\((?P<malkovichMalkovich>-?\d+|range\(-?\d+,-?\d+\)),(?P<multiplyIDK>\d+)\)(?P<joinBehind>,)|"
|
|
154
177
|
#Pattern 3: Bracket ahead, bracket behind
|
|
155
|
-
r"(?P<bracketAhead>\[)\((?P<malkovichMalkovichMalkovich
|
|
178
|
+
r"(?P<bracketAhead>\[)\((?P<malkovichMalkovichMalkovich>-?\d+|range\(-?\d+,-?\d+\)),(?P<multiply_whatever>\d+)\)(?P<bracketBehindBracketBehind>])|"
|
|
156
179
|
#Pattern 4: Comma ahead, comma behind
|
|
157
|
-
r"(?P<joinAheadJoinAhead>,)\((?P<malkovichMalkovichMalkovichMalkovich
|
|
180
|
+
r"(?P<joinAheadJoinAhead>,)\((?P<malkovichMalkovichMalkovichMalkovich>-?\d+|range\(-?\d+,-?\d+\)),(?P<multiplyOrSomething>\d+)\)(?P<joinBehindJoinBehind>,)"
|
|
158
181
|
r")"
|
|
159
182
|
)
|
|
160
183
|
|
|
161
184
|
def replacementByContext(match: regex.Match[str]) -> str:
|
|
162
|
-
"""
|
|
185
|
+
"""I use this replacement to express a repeated value with Python list multiplication.
|
|
186
|
+
|
|
187
|
+
(AI generated docstring)
|
|
188
|
+
|
|
189
|
+
The replacement joins the repeated list with any surrounding list elements so that
|
|
190
|
+
the resulting expression preserves the decoded values and their order.
|
|
191
|
+
"""
|
|
163
192
|
elephino: dict[str, str | None] = match.groupdict()
|
|
164
193
|
joinAhead: str | None = elephino.get('joinAhead') or elephino.get('joinAheadJoinAhead')
|
|
165
194
|
malkovich: str | None = elephino.get('malkovich') or elephino.get('malkovichMalkovich') or elephino.get('malkovichMalkovichMalkovich') or elephino.get('malkovichMalkovichMalkovichMalkovich')
|
|
@@ -182,17 +211,44 @@ def autoDecodingRLE(arrayTarget: NDArray[integer[Any]], *, assumeAddSpaces: bool
|
|
|
182
211
|
def stringItUp(*scrapPile: Any) -> list[str]:
|
|
183
212
|
"""Convert, if possible, every element in the input data structure to a string.
|
|
184
213
|
|
|
185
|
-
|
|
214
|
+
(AI generated docstring)
|
|
215
|
+
|
|
216
|
+
You can collect text from nested inputs into a flat `list`. Dictionaries contribute both keys
|
|
217
|
+
and values. Strings contribute their full text, and callables contribute their names.
|
|
186
218
|
|
|
187
219
|
Parameters
|
|
188
220
|
----------
|
|
189
221
|
*scrapPile : Any
|
|
190
|
-
(scrap2pile)
|
|
222
|
+
(scrap2pile) Values or nested data structures to unpack and convert. No arguments produce
|
|
223
|
+
an empty `list`. `bytes` and `bytearray` contribute their Python string representations.
|
|
224
|
+
A `memoryview` contributes decoded text when text decoding succeeds. Other iterables
|
|
225
|
+
contribute their elements and are consumed.
|
|
191
226
|
|
|
192
227
|
Returns
|
|
193
228
|
-------
|
|
194
229
|
listStrungUp : list[str]
|
|
195
|
-
(list2strung2up) A `list` of string
|
|
230
|
+
(list2strung2up) A flat `list` of string representations. The result follows argument order
|
|
231
|
+
and container iteration order. Unordered containers can make the result order unpredictable.
|
|
232
|
+
|
|
233
|
+
Incomplete Conversion
|
|
234
|
+
---------------------
|
|
235
|
+
Other non-iterable values contribute their string representations. String conversion that
|
|
236
|
+
returns `None` or raises `AttributeError` or `TypeError` omits those values. Other exceptions
|
|
237
|
+
from that conversion produce a diagnostic on `sys.stderr` and propagate.
|
|
238
|
+
|
|
239
|
+
If recursive input exceeds Python's recursion limit, the result retains text already collected
|
|
240
|
+
and appends `repr` of the current top-level argument. Later arguments are not processed.
|
|
241
|
+
|
|
242
|
+
Examples
|
|
243
|
+
--------
|
|
244
|
+
The README collects text from nested user and configuration data.
|
|
245
|
+
|
|
246
|
+
```python
|
|
247
|
+
from hunterMakesPy.dataStructures import stringItUp
|
|
248
|
+
|
|
249
|
+
strings = stringItUp({"users": ["alice"], "config": {"host": "localhost"}})
|
|
250
|
+
# Returns ["users", "alice", "config", "host", "localhost"].
|
|
251
|
+
```
|
|
196
252
|
"""
|
|
197
253
|
scrap: Any = None
|
|
198
254
|
listStrungUp: list[str] = []
|
|
@@ -225,8 +281,9 @@ def stringItUp(*scrapPile: Any) -> list[str]:
|
|
|
225
281
|
else:
|
|
226
282
|
try:
|
|
227
283
|
#ruff: ignore[unnecessary-dunder-call]
|
|
228
|
-
sharingIsCaring: str = KitKat.__str__()
|
|
229
|
-
|
|
284
|
+
sharingIsCaring: str | None = KitKat.__str__()
|
|
285
|
+
if sharingIsCaring is not None:
|
|
286
|
+
listStrungUp.append(sharingIsCaring)
|
|
230
287
|
except AttributeError:
|
|
231
288
|
pass
|
|
232
289
|
except TypeError:
|
|
@@ -255,24 +312,23 @@ def updateExtendPolishDictionaryLists(*dictionaryLists: Mapping[文件, Iterable
|
|
|
255
312
|
def updateExtendPolishDictionaryLists(*dictionaryLists: Mapping[文件, Iterable[文义]], destroyDuplicates: bool = False, reorderLists: bool = False, killErroneousDataTypes: bool = False) -> dict[文件, list[文义]]:
|
|
256
313
|
"""Merge mappings of iterable values into a dictionary of lists.
|
|
257
314
|
|
|
258
|
-
|
|
259
|
-
This function returns a new dictionary with new lists and can remove duplicate elements,
|
|
260
|
-
sort elements, or skip entries that raise `TypeError` during merging.
|
|
315
|
+
(AI generated docstring)
|
|
261
316
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
the list follows the iterable's order, which may be unpredictable for sets. Strings contribute
|
|
266
|
-
individual characters, and mapping values contribute their keys.
|
|
317
|
+
You can use this function to combine values under matching keys across `dictionaryLists`.
|
|
318
|
+
You receive a new dictionary with new lists and can remove duplicate elements, sort elements,
|
|
319
|
+
or skip entries that raise `TypeError` during merging.
|
|
267
320
|
|
|
268
|
-
|
|
269
|
-
|
|
321
|
+
Input Consumption
|
|
322
|
+
-----------------
|
|
323
|
+
The input mappings and reusable value containers remain unchanged. Iterable values such as
|
|
324
|
+
generators are consumed. Each result list retains references to the original elements.
|
|
270
325
|
|
|
271
326
|
Parameters
|
|
272
327
|
----------
|
|
273
328
|
*dictionaryLists : Mapping[文件, Iterable[文义]]
|
|
274
329
|
The mappings to merge, with hashable keys and iterable values. A single mapping receives
|
|
275
|
-
the same conversion and optional processing.
|
|
330
|
+
the same conversion and optional processing. Omitting all mappings produces an empty
|
|
331
|
+
dictionary. Strings contribute individual characters. Mapping values contribute their keys.
|
|
276
332
|
destroyDuplicates : bool = False
|
|
277
333
|
If `True`, remove duplicate elements from each merged list, preserving the first occurrence.
|
|
278
334
|
Elements must be hashable when this option is enabled.
|
|
@@ -287,8 +343,9 @@ def updateExtendPolishDictionaryLists(*dictionaryLists: Mapping[文件, Iterable
|
|
|
287
343
|
Returns
|
|
288
344
|
-------
|
|
289
345
|
ePluribusUnum : dict[文件, list[文义]]
|
|
290
|
-
The merged dictionary, with a list for every retained key.
|
|
291
|
-
|
|
346
|
+
The merged dictionary, with a new list for every retained key. Mapping argument order and
|
|
347
|
+
each value's iteration order determine element order unless `reorderLists` is `True`.
|
|
348
|
+
Unordered inputs, such as sets, may produce unpredictable element order.
|
|
292
349
|
|
|
293
350
|
Raises
|
|
294
351
|
------
|
|
@@ -312,10 +369,6 @@ def updateExtendPolishDictionaryLists(*dictionaryLists: Mapping[文件, Iterable
|
|
|
312
369
|
# Returns {"servers": ["chicago", "tokyo"]}.
|
|
313
370
|
```
|
|
314
371
|
|
|
315
|
-
References
|
|
316
|
-
----------
|
|
317
|
-
[1] Python dictionaries and `dict.fromkeys`.
|
|
318
|
-
https://docs.python.org/3/library/stdtypes.html#dict.fromkeys
|
|
319
372
|
"""
|
|
320
373
|
ePluribusUnum: dict[文件, list[文义]] = {}
|
|
321
374
|
|