mapFolding 0.8.4__py3-none-any.whl → 0.8.5__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.
- mapFolding/__init__.py +4 -1
- mapFolding/basecamp.py +3 -3
- mapFolding/beDRY.py +241 -68
- mapFolding/oeis.py +3 -3
- mapFolding/reference/hunterNumba.py +1 -1
- mapFolding/someAssemblyRequired/__init__.py +16 -15
- mapFolding/someAssemblyRequired/_theTypes.py +31 -13
- mapFolding/someAssemblyRequired/_tool_Make.py +8 -1
- mapFolding/someAssemblyRequired/_tool_Then.py +12 -5
- mapFolding/someAssemblyRequired/_toolboxAntecedents.py +131 -99
- mapFolding/someAssemblyRequired/_toolboxContainers.py +35 -7
- mapFolding/someAssemblyRequired/_toolboxPython.py +17 -31
- mapFolding/someAssemblyRequired/getLLVMforNoReason.py +2 -2
- mapFolding/someAssemblyRequired/newInliner.py +22 -0
- mapFolding/someAssemblyRequired/synthesizeNumbaJob.py +24 -113
- mapFolding/someAssemblyRequired/toolboxNumba.py +358 -0
- mapFolding/someAssemblyRequired/transformationTools.py +253 -40
- mapFolding/theSSOT.py +30 -32
- mapFolding/{filesystem.py → toolboxFilesystem.py} +90 -25
- {mapfolding-0.8.4.dist-info → mapfolding-0.8.5.dist-info}/METADATA +3 -2
- mapfolding-0.8.5.dist-info/RECORD +48 -0
- tests/conftest.py +30 -31
- tests/test_computations.py +7 -6
- tests/test_filesystem.py +2 -2
- tests/test_other.py +2 -2
- tests/test_tasks.py +2 -2
- mapFolding/someAssemblyRequired/ingredientsNumba.py +0 -199
- mapFolding/someAssemblyRequired/synthesizeNumbaFlow.py +0 -156
- mapFolding/someAssemblyRequired/transformDataStructures.py +0 -235
- mapfolding-0.8.4.dist-info/RECORD +0 -49
- {mapfolding-0.8.4.dist-info → mapfolding-0.8.5.dist-info}/WHEEL +0 -0
- {mapfolding-0.8.4.dist-info → mapfolding-0.8.5.dist-info}/entry_points.txt +0 -0
- {mapfolding-0.8.4.dist-info → mapfolding-0.8.5.dist-info}/licenses/LICENSE +0 -0
- {mapfolding-0.8.4.dist-info → mapfolding-0.8.5.dist-info}/top_level.txt +0 -0
|
@@ -1,9 +1,65 @@
|
|
|
1
1
|
from collections.abc import Callable, Container
|
|
2
|
-
from mapFolding.someAssemblyRequired import
|
|
3
|
-
|
|
2
|
+
from mapFolding.someAssemblyRequired import (
|
|
3
|
+
ast_expr_Slice,
|
|
4
|
+
ast_Identifier,
|
|
5
|
+
Ima_funcTypeUNEDITED,
|
|
6
|
+
astClassHasDOTnameNotName,
|
|
7
|
+
astClassOptionallyHasDOTnameNotName,
|
|
8
|
+
astClassHasDOTtarget,
|
|
9
|
+
astClassHasDOTvalue,
|
|
10
|
+
ImaAnnotationType,
|
|
11
|
+
ImaAnnotationTypeVar,
|
|
12
|
+
Ima_targetTypeUNEDITED,
|
|
13
|
+
TypeCertified,
|
|
14
|
+
)
|
|
15
|
+
from typing import Any, cast, overload, TypeGuard
|
|
4
16
|
import ast
|
|
5
17
|
|
|
6
|
-
|
|
18
|
+
class NotMyProblem(Exception):
|
|
19
|
+
pass
|
|
20
|
+
|
|
21
|
+
class DOT:
|
|
22
|
+
@staticmethod
|
|
23
|
+
@overload
|
|
24
|
+
def annotation(node: ast.AnnAssign) -> ImaAnnotationType:...
|
|
25
|
+
@staticmethod
|
|
26
|
+
@overload
|
|
27
|
+
def annotation(node: ast.arg) -> ImaAnnotationType | None:...
|
|
28
|
+
@staticmethod
|
|
29
|
+
def annotation(node: ast.AnnAssign | ast.arg) -> ImaAnnotationType | None:
|
|
30
|
+
return cast(ImaAnnotationType, node.annotation)
|
|
31
|
+
# fu = node.annotation
|
|
32
|
+
# if fu is None:
|
|
33
|
+
# return None
|
|
34
|
+
# else:
|
|
35
|
+
# fu = cast(ImaAnnotationType, node.annotation)
|
|
36
|
+
# return fu
|
|
37
|
+
@staticmethod
|
|
38
|
+
def func(node: ast.Call) -> Ima_funcTypeUNEDITED | ast.expr:
|
|
39
|
+
return node.func
|
|
40
|
+
@staticmethod
|
|
41
|
+
def id(node: ast.Name) -> ast_Identifier:
|
|
42
|
+
return node.id
|
|
43
|
+
@staticmethod
|
|
44
|
+
def name(node: astClassHasDOTnameNotName | astClassOptionallyHasDOTnameNotName) -> ast_Identifier:
|
|
45
|
+
if isinstance(node, astClassHasDOTnameNotName):
|
|
46
|
+
return node.name
|
|
47
|
+
try:
|
|
48
|
+
identifier = node.name
|
|
49
|
+
if identifier is None:
|
|
50
|
+
raise NotMyProblem
|
|
51
|
+
return identifier
|
|
52
|
+
except AttributeError:
|
|
53
|
+
raise NotMyProblem
|
|
54
|
+
|
|
55
|
+
@staticmethod
|
|
56
|
+
def nameOrNone(node: astClassHasDOTnameNotName | astClassOptionallyHasDOTnameNotName) -> ast_Identifier | None:
|
|
57
|
+
if isinstance(node, astClassHasDOTnameNotName):
|
|
58
|
+
return node.name
|
|
59
|
+
try:
|
|
60
|
+
return node.name
|
|
61
|
+
except AttributeError:
|
|
62
|
+
return None
|
|
7
63
|
|
|
8
64
|
class 又:
|
|
9
65
|
@staticmethod
|
|
@@ -76,79 +132,64 @@ class 又:
|
|
|
76
132
|
|
|
77
133
|
class be:
|
|
78
134
|
@staticmethod
|
|
79
|
-
def _typeCertified(antecedent: type[
|
|
80
|
-
def workhorse(node: Any | None) -> TypeGuard[
|
|
135
|
+
def _typeCertified(antecedent: type[TypeCertified]) -> Callable[[Any | None], TypeGuard[TypeCertified]]:
|
|
136
|
+
def workhorse(node: Any | None) -> TypeGuard[TypeCertified]:
|
|
81
137
|
return isinstance(node, antecedent)
|
|
82
138
|
return workhorse
|
|
83
139
|
@staticmethod
|
|
84
|
-
def AnnAssign(node:
|
|
85
|
-
# 'TypeVar "typeCertified" appears only once in generic function signature. Use "
|
|
140
|
+
def AnnAssign(node: TypeCertified) -> TypeGuard[ast.AnnAssign]: return be._typeCertified(ast.AnnAssign)(node) # pyright: ignore [reportInvalidTypeVarUse]
|
|
141
|
+
# 'TypeVar "typeCertified" appears only once in generic function signature. Use "typeCertified" instead Pylance(reportInvalidTypeVarUse)"' HOW THE FUCK IS THAT INVALID WHEN IT IS WORKING PERFECTLY TO PASS THE TYPE INFORMATION--IN YOUR FUCKING STATIC TYPE CHECKER, PYLANCE!!!! Fuck you, and fuck your pretentious language.
|
|
86
142
|
@staticmethod
|
|
87
|
-
def arg(node:
|
|
88
|
-
|
|
89
|
-
# @staticmethod
|
|
90
|
-
# def Annotation(node: ast.AST) -> TypeGuard[object] | bool:
|
|
91
|
-
# if be.Attribute(node):
|
|
92
|
-
# return be.Attribute(node)
|
|
93
|
-
# elif be.Constant(node):
|
|
94
|
-
# return be.Constant(node)
|
|
95
|
-
# elif be.Name(node):
|
|
96
|
-
# return be.Name(node)
|
|
97
|
-
# elif be.Subscript(node):
|
|
98
|
-
# return be.Subscript(node)
|
|
99
|
-
# else:
|
|
100
|
-
# return False
|
|
101
|
-
# return be.Attribute(node) or be.Constant(node) or be.Name(node) or be.Subscript(node)
|
|
102
|
-
|
|
143
|
+
def arg(node: TypeCertified) -> TypeGuard[ast.arg]: return be._typeCertified(ast.arg)(node) # pyright: ignore [reportInvalidTypeVarUse]
|
|
103
144
|
@staticmethod
|
|
104
|
-
def Assign(node:
|
|
145
|
+
def Assign(node: TypeCertified) -> TypeGuard[ast.Assign]: return be._typeCertified(ast.Assign)(node) # pyright: ignore [reportInvalidTypeVarUse]
|
|
105
146
|
@staticmethod
|
|
106
|
-
def Attribute(node:
|
|
147
|
+
def Attribute(node: TypeCertified) -> TypeGuard[ast.Attribute]: return be._typeCertified(ast.Attribute)(node) # pyright: ignore [reportInvalidTypeVarUse]
|
|
107
148
|
@staticmethod
|
|
108
|
-
def AugAssign(node:
|
|
149
|
+
def AugAssign(node: TypeCertified) -> TypeGuard[ast.AugAssign]: return be._typeCertified(ast.AugAssign)(node) # pyright: ignore [reportInvalidTypeVarUse]
|
|
109
150
|
@staticmethod
|
|
110
|
-
def BoolOp(node:
|
|
151
|
+
def BoolOp(node: TypeCertified) -> TypeGuard[ast.BoolOp]: return be._typeCertified(ast.BoolOp)(node) # pyright: ignore [reportInvalidTypeVarUse]
|
|
111
152
|
@staticmethod
|
|
112
|
-
def Call(node:
|
|
153
|
+
def Call(node: TypeCertified) -> TypeGuard[ast.Call]: return be._typeCertified(ast.Call)(node) # pyright: ignore [reportInvalidTypeVarUse]
|
|
113
154
|
@staticmethod
|
|
114
|
-
def ClassDef(node:
|
|
155
|
+
def ClassDef(node: TypeCertified) -> TypeGuard[ast.ClassDef]: return be._typeCertified(ast.ClassDef)(node) # pyright: ignore [reportInvalidTypeVarUse]
|
|
115
156
|
@staticmethod
|
|
116
|
-
def Compare(node:
|
|
157
|
+
def Compare(node: TypeCertified) -> TypeGuard[ast.Compare]: return be._typeCertified(ast.Compare)(node) # pyright: ignore [reportInvalidTypeVarUse]
|
|
117
158
|
@staticmethod
|
|
118
|
-
def Constant(node:
|
|
159
|
+
def Constant(node: TypeCertified) -> TypeGuard[ast.Constant]: return be._typeCertified(ast.Constant)(node) # pyright: ignore [reportInvalidTypeVarUse]
|
|
119
160
|
@staticmethod
|
|
120
|
-
def Expr(node:
|
|
161
|
+
def Expr(node: TypeCertified) -> TypeGuard[ast.Expr]: return be._typeCertified(ast.Expr)(node) # pyright: ignore [reportInvalidTypeVarUse]
|
|
121
162
|
@staticmethod
|
|
122
|
-
def FunctionDef(node:
|
|
163
|
+
def FunctionDef(node: TypeCertified) -> TypeGuard[ast.FunctionDef]: return be._typeCertified(ast.FunctionDef)(node) # pyright: ignore [reportInvalidTypeVarUse]
|
|
123
164
|
@staticmethod
|
|
124
|
-
def Import(node:
|
|
165
|
+
def Import(node: TypeCertified) -> TypeGuard[ast.Import]: return be._typeCertified(ast.Import)(node) # pyright: ignore [reportInvalidTypeVarUse]
|
|
125
166
|
@staticmethod
|
|
126
|
-
def ImportFrom(node:
|
|
167
|
+
def ImportFrom(node: TypeCertified) -> TypeGuard[ast.ImportFrom]: return be._typeCertified(ast.ImportFrom)(node) # pyright: ignore [reportInvalidTypeVarUse]
|
|
127
168
|
@staticmethod
|
|
128
|
-
def keyword(node:
|
|
169
|
+
def keyword(node: TypeCertified) -> TypeGuard[ast.keyword]: return be._typeCertified(ast.keyword)(node) # pyright: ignore [reportInvalidTypeVarUse]
|
|
129
170
|
@staticmethod
|
|
130
|
-
def Module(node:
|
|
171
|
+
def Module(node: TypeCertified) -> TypeGuard[ast.Module]: return be._typeCertified(ast.Module)(node) # pyright: ignore [reportInvalidTypeVarUse]
|
|
131
172
|
@staticmethod
|
|
132
|
-
def Name(node:
|
|
173
|
+
def Name(node: TypeCertified) -> TypeGuard[ast.Name]: return be._typeCertified(ast.Name)(node) # pyright: ignore [reportInvalidTypeVarUse]
|
|
133
174
|
@staticmethod
|
|
134
|
-
def Return(node:
|
|
175
|
+
def Return(node: TypeCertified) -> TypeGuard[ast.Return]: return be._typeCertified(ast.Return)(node) # pyright: ignore [reportInvalidTypeVarUse]
|
|
135
176
|
@staticmethod
|
|
136
|
-
def Starred(node:
|
|
177
|
+
def Starred(node: TypeCertified) -> TypeGuard[ast.Starred]: return be._typeCertified(ast.Starred)(node) # pyright: ignore [reportInvalidTypeVarUse]
|
|
137
178
|
@staticmethod
|
|
138
|
-
def Subscript(node:
|
|
179
|
+
def Subscript(node: TypeCertified) -> TypeGuard[ast.Subscript]: return be._typeCertified(ast.Subscript)(node) # pyright: ignore [reportInvalidTypeVarUse]
|
|
139
180
|
@staticmethod
|
|
140
|
-
def UnaryOp(node:
|
|
181
|
+
def UnaryOp(node: TypeCertified) -> TypeGuard[ast.UnaryOp]: return be._typeCertified(ast.UnaryOp)(node) # pyright: ignore [reportInvalidTypeVarUse]
|
|
141
182
|
|
|
142
183
|
class ifThis:
|
|
143
184
|
@staticmethod
|
|
144
185
|
def equals(this: Any) -> Callable[[Any], TypeGuard[Any] | bool]:
|
|
145
186
|
return lambda node: node == this
|
|
146
187
|
@staticmethod
|
|
147
|
-
def isAssignAndTargets0Is(targets0Predicate: Callable[[ast.AST], bool]) -> Callable[[ast.AST], TypeGuard[
|
|
188
|
+
def isAssignAndTargets0Is(targets0Predicate: Callable[[ast.AST], bool]) -> Callable[[ast.AST], TypeGuard[ast.AnnAssign] | bool]:
|
|
148
189
|
"""node is Assign and node.targets[0] matches `targets0Predicate`."""
|
|
149
190
|
return lambda node: be.Assign(node) and targets0Predicate(node.targets[0])
|
|
150
191
|
@staticmethod
|
|
151
|
-
def isAssignAndValueIs(valuePredicate: Callable[[ast.AST], bool]) -> Callable[[ast.AST], TypeGuard[
|
|
192
|
+
def isAssignAndValueIs(valuePredicate: Callable[[ast.AST], bool]) -> Callable[[ast.AST], TypeGuard[ast.Assign] | bool]:
|
|
152
193
|
"""node is ast.Assign and node.value matches `valuePredicate`.
|
|
153
194
|
Parameters:
|
|
154
195
|
valuePredicate: Function that evaluates the value of the assignment
|
|
@@ -157,101 +198,92 @@ class ifThis:
|
|
|
157
198
|
"""
|
|
158
199
|
return lambda node: be.Assign(node) and 又.value(valuePredicate)(node)
|
|
159
200
|
@staticmethod
|
|
160
|
-
def isFunctionDef_Identifier(identifier: ast_Identifier) -> Callable[[ast.AST], TypeGuard[
|
|
201
|
+
def isFunctionDef_Identifier(identifier: ast_Identifier) -> Callable[[ast.AST], TypeGuard[ast.FunctionDef] | bool]:
|
|
161
202
|
return lambda node: be.FunctionDef(node) and 又.name(ifThis._Identifier(identifier))(node)
|
|
162
203
|
@staticmethod
|
|
163
|
-
def isArgument_Identifier(identifier: ast_Identifier) -> Callable[[ast.AST], TypeGuard[
|
|
204
|
+
def isArgument_Identifier(identifier: ast_Identifier) -> Callable[[ast.AST], TypeGuard[ast.arg | ast.keyword] | bool]:
|
|
164
205
|
return lambda node: (be.arg(node) or be.keyword(node)) and 又.arg(ifThis._Identifier(identifier))(node)
|
|
165
206
|
@staticmethod
|
|
166
|
-
def is_keyword_Identifier(identifier: ast_Identifier) -> Callable[[ast.AST], TypeGuard[
|
|
207
|
+
def is_keyword_Identifier(identifier: ast_Identifier) -> Callable[[ast.AST], TypeGuard[ast.keyword] | bool]:
|
|
167
208
|
"""see also `isArgument_Identifier`"""
|
|
168
209
|
return lambda node: be.keyword(node) and 又.arg(ifThis._Identifier(identifier))(node)
|
|
169
210
|
@staticmethod
|
|
170
|
-
def is_arg_Identifier(identifier: ast_Identifier) -> Callable[[ast.AST], TypeGuard[
|
|
211
|
+
def is_arg_Identifier(identifier: ast_Identifier) -> Callable[[ast.AST], TypeGuard[ast.arg] | bool]:
|
|
171
212
|
"""see also `isArgument_Identifier`"""
|
|
172
213
|
return lambda node: be.arg(node) and 又.arg(ifThis._Identifier(identifier))(node)
|
|
173
214
|
@staticmethod
|
|
174
|
-
def isClassDef_Identifier(identifier: ast_Identifier) -> Callable[[ast.AST], TypeGuard[
|
|
215
|
+
def isClassDef_Identifier(identifier: ast_Identifier) -> Callable[[ast.AST], TypeGuard[ast.ClassDef] | bool]:
|
|
175
216
|
return lambda node: be.ClassDef(node) and 又.name(ifThis._Identifier(identifier))(node)
|
|
176
217
|
@staticmethod
|
|
177
|
-
def isAssignAndValueIsCall_Identifier(identifier: ast_Identifier) -> Callable[[ast.AST], TypeGuard[
|
|
218
|
+
def isAssignAndValueIsCall_Identifier(identifier: ast_Identifier) -> Callable[[ast.AST], TypeGuard[ast.Assign] | bool]:
|
|
178
219
|
return lambda node: be.Assign(node) and 又.value(ifThis.isCall_Identifier(identifier))(node)
|
|
179
220
|
@staticmethod
|
|
180
|
-
def isAssignAndValueIsCallAttributeNamespace_Identifier(namespace: ast_Identifier, identifier: ast_Identifier) -> Callable[[ast.AST], TypeGuard[
|
|
221
|
+
def isAssignAndValueIsCallAttributeNamespace_Identifier(namespace: ast_Identifier, identifier: ast_Identifier) -> Callable[[ast.AST], TypeGuard[ast.Assign] | bool]:
|
|
181
222
|
return ifThis.isAssignAndValueIs(ifThis.isCallAttributeNamespace_Identifier(namespace, identifier))
|
|
182
223
|
@staticmethod
|
|
183
|
-
def is_keywordAndValueIsConstant(node:
|
|
224
|
+
def is_keywordAndValueIsConstant(node: TypeCertified) -> TypeGuard[ast.keyword]: # pyright: ignore [reportInvalidTypeVarUse]
|
|
184
225
|
return be.keyword(node) and 又.value(be.Constant)(node)
|
|
185
226
|
@staticmethod
|
|
186
|
-
def is_keyword_IdentifierEqualsConstantValue(identifier: ast_Identifier, ConstantValue: Any) -> Callable[[ast.AST], TypeGuard[
|
|
227
|
+
def is_keyword_IdentifierEqualsConstantValue(identifier: ast_Identifier, ConstantValue: Any) -> Callable[[ast.AST], TypeGuard[ast.keyword] | bool]:
|
|
187
228
|
return lambda node: ifThis.is_keyword_Identifier(identifier)(node) and ifThis.is_keywordAndValueIsConstant(node) and 又.value(ifThis.isConstantEquals(ConstantValue))(node)
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
"object*" is not assignable to "AnnAssign"
|
|
192
|
-
"object*" is not assignable to "AsyncFor"
|
|
193
|
-
"object*" is not assignable to "AugAssign"
|
|
194
|
-
"object*" is not assignable to "comprehension"
|
|
195
|
-
"object*" is not assignable to "For"
|
|
196
|
-
"object*" is not assignable to "NamedExpr"
|
|
197
|
-
"""
|
|
198
|
-
@staticmethod
|
|
199
|
-
def isAnnAssign_targetIs(targetPredicate: Callable[[Ima_targetType], TypeGuard[Ima_targetType] | bool]) -> Callable[[ast.AST], TypeGuard[object] | bool]:
|
|
200
|
-
def workhorse(node: ast.AST) -> TypeGuard[object] | bool:
|
|
229
|
+
@staticmethod
|
|
230
|
+
def isAnnAssign_targetIs(targetPredicate: Callable[[Ima_targetTypeUNEDITED], TypeGuard[Ima_targetTypeUNEDITED] | bool]) -> Callable[[ast.AST], TypeGuard[ast.AnnAssign] | bool]:
|
|
231
|
+
def workhorse(node: TypeCertified) -> TypeGuard[ast.AnnAssign] | bool: # pyright: ignore [reportInvalidTypeVarUse]
|
|
201
232
|
return be.AnnAssign(node) and 又.target(targetPredicate)(node)
|
|
202
233
|
return workhorse
|
|
203
234
|
@staticmethod
|
|
204
|
-
def isAnnAssignAndAnnotationIsName(node:
|
|
205
|
-
return be.AnnAssign(node) and
|
|
235
|
+
def isAnnAssignAndAnnotationIsName(node: TypeCertified) -> TypeGuard[ast.AnnAssign] | bool: # pyright: ignore [reportInvalidTypeVarUse]
|
|
236
|
+
return be.AnnAssign(node) and be.Name(DOT.annotation(node))
|
|
237
|
+
# return be.AnnAssign(node) and 又.annotation(be.Name)(node)
|
|
206
238
|
@staticmethod
|
|
207
|
-
def isAugAssign_targetIs(targetPredicate: Callable[[
|
|
208
|
-
def workhorse(node:
|
|
239
|
+
def isAugAssign_targetIs(targetPredicate: Callable[[Ima_targetTypeUNEDITED], TypeGuard[Ima_targetTypeUNEDITED] | bool]) -> Callable[[ast.AST], TypeGuard[ast.AugAssign] | bool]:
|
|
240
|
+
def workhorse(node: TypeCertified) -> TypeGuard[ast.AugAssign] | bool: # pyright: ignore [reportInvalidTypeVarUse]
|
|
209
241
|
return be.AugAssign(node) and 又.target(targetPredicate)(node)
|
|
210
242
|
return workhorse
|
|
211
243
|
|
|
212
244
|
@staticmethod
|
|
213
|
-
def isAnyCompare(node:
|
|
245
|
+
def isAnyCompare(node: TypeCertified) -> TypeGuard[ast.BoolOp | ast.Compare]: # pyright: ignore [reportInvalidTypeVarUse]
|
|
214
246
|
return be.Compare(node) or be.BoolOp(node)
|
|
215
247
|
@staticmethod
|
|
216
|
-
def isConstantEquals(value: Any) -> Callable[[ast.AST], TypeGuard[
|
|
248
|
+
def isConstantEquals(value: Any) -> Callable[[ast.AST], TypeGuard[ast.Constant] | bool]:
|
|
217
249
|
return lambda node: be.Constant(node) and 又.value(ifThis.equals(value))(node)
|
|
218
250
|
@staticmethod
|
|
219
|
-
def isReturnAnyCompare(node:
|
|
251
|
+
def isReturnAnyCompare(node: TypeCertified) -> TypeGuard[ast.Return] | bool: # pyright: ignore [reportInvalidTypeVarUse] # pyright: ignore [reportInvalidTypeVarUse]
|
|
220
252
|
return be.Return(node) and 又.value(ifThis.isAnyCompare)(node)
|
|
221
253
|
@staticmethod
|
|
222
|
-
def isReturnUnaryOp(node:
|
|
254
|
+
def isReturnUnaryOp(node: TypeCertified) -> TypeGuard[ast.Return] | bool: # pyright: ignore [reportInvalidTypeVarUse]
|
|
223
255
|
return be.Return(node) and 又.value(be.UnaryOp)(node)
|
|
224
256
|
|
|
225
257
|
# ================================================================
|
|
226
258
|
# Nested identifier
|
|
227
259
|
@staticmethod
|
|
228
|
-
def _nestedJunction_Identifier(identifier: ast_Identifier) -> Callable[[ast.AST], TypeGuard[
|
|
229
|
-
def workhorse(node:
|
|
260
|
+
def _nestedJunction_Identifier(identifier: ast_Identifier) -> Callable[[ast.AST], TypeGuard[ast.Attribute | ast.Starred | ast.Subscript] | bool]:
|
|
261
|
+
def workhorse(node: TypeCertified) -> TypeGuard[ast.Attribute | ast.Starred | ast.Subscript] | bool: # pyright: ignore [reportInvalidTypeVarUse]
|
|
230
262
|
return ifThis.isName_Identifier(identifier)(node) or ifThis.isAttribute_Identifier(identifier)(node) or ifThis.isSubscript_Identifier(identifier)(node) or ifThis.isStarred_Identifier(identifier)(node)
|
|
231
263
|
return workhorse
|
|
232
264
|
@staticmethod
|
|
233
|
-
def isAttribute_Identifier(identifier: ast_Identifier) -> Callable[[ast.AST], TypeGuard[
|
|
265
|
+
def isAttribute_Identifier(identifier: ast_Identifier) -> Callable[[ast.AST], TypeGuard[ast.Attribute] | bool]:
|
|
234
266
|
"""node is `ast.Attribute` and the top-level `ast.Name` is `identifier`"""
|
|
235
|
-
def workhorse(node:
|
|
267
|
+
def workhorse(node: TypeCertified) -> TypeGuard[ast.Attribute]: # pyright: ignore [reportInvalidTypeVarUse]
|
|
236
268
|
return be.Attribute(node) and 又.value(ifThis._nestedJunction_Identifier(identifier))(node)
|
|
237
269
|
return workhorse
|
|
238
270
|
@staticmethod
|
|
239
|
-
def isStarred_Identifier(identifier: ast_Identifier) -> Callable[[ast.AST], TypeGuard[
|
|
271
|
+
def isStarred_Identifier(identifier: ast_Identifier) -> Callable[[ast.AST], TypeGuard[ast.Starred] | bool]:
|
|
240
272
|
"""node is `ast.Starred` and the top-level `ast.Name` is `identifier`"""
|
|
241
|
-
def workhorse(node:
|
|
273
|
+
def workhorse(node: TypeCertified) -> TypeGuard[ast.Starred]: # pyright: ignore [reportInvalidTypeVarUse]
|
|
242
274
|
return be.Starred(node) and 又.value(ifThis._nestedJunction_Identifier(identifier))(node)
|
|
243
275
|
return workhorse
|
|
244
276
|
@staticmethod
|
|
245
|
-
def isSubscript_Identifier(identifier: ast_Identifier) -> Callable[[ast.AST], TypeGuard[
|
|
277
|
+
def isSubscript_Identifier(identifier: ast_Identifier) -> Callable[[ast.AST], TypeGuard[ast.Subscript] | bool]:
|
|
246
278
|
"""node is `ast.Subscript` and the top-level `ast.Name` is `identifier`"""
|
|
247
|
-
def workhorse(node:
|
|
279
|
+
def workhorse(node: TypeCertified) -> TypeGuard[ast.Subscript]: # pyright: ignore [reportInvalidTypeVarUse]
|
|
248
280
|
return be.Subscript(node) and 又.value(ifThis._nestedJunction_Identifier(identifier))(node)
|
|
249
281
|
return workhorse
|
|
250
282
|
# ================================================================
|
|
251
283
|
|
|
252
284
|
@staticmethod
|
|
253
285
|
def Z0Z_unparseIs(astAST: ast.AST) -> Callable[[ast.AST], bool]:
|
|
254
|
-
def workhorse(node:
|
|
286
|
+
def workhorse(node: TypeCertified) -> bool: return ast.unparse(node) == ast.unparse(astAST) # pyright: ignore [reportInvalidTypeVarUse]
|
|
255
287
|
return workhorse
|
|
256
288
|
|
|
257
289
|
# ================================================================
|
|
@@ -264,32 +296,36 @@ Argument of type "typeCertified@isAnnAssign_targetIs" cannot be assigned to para
|
|
|
264
296
|
# ================================================================
|
|
265
297
|
# MORE function inlining
|
|
266
298
|
@staticmethod
|
|
267
|
-
def onlyReturnAnyCompare(astFunctionDef: ast.AST) -> TypeGuard[
|
|
299
|
+
def onlyReturnAnyCompare(astFunctionDef: ast.AST) -> TypeGuard[ast.FunctionDef] | bool:
|
|
268
300
|
return be.FunctionDef(astFunctionDef) and len(astFunctionDef.body) == 1 and ifThis.isReturnAnyCompare(astFunctionDef.body[0])
|
|
269
301
|
# For function inlining
|
|
270
302
|
@staticmethod
|
|
271
|
-
def onlyReturnUnaryOp(astFunctionDef: ast.AST) -> TypeGuard[
|
|
303
|
+
def onlyReturnUnaryOp(astFunctionDef: ast.AST) -> TypeGuard[ast.FunctionDef] | bool:
|
|
272
304
|
return be.FunctionDef(astFunctionDef) and len(astFunctionDef.body) == 1 and ifThis.isReturnUnaryOp(astFunctionDef.body[0])
|
|
273
305
|
# ================================================================
|
|
274
306
|
# These are used by other functions
|
|
275
307
|
@staticmethod
|
|
276
|
-
def isCallAttributeNamespace_Identifier(namespace: ast_Identifier, identifier: ast_Identifier) -> Callable[[ast.AST], TypeGuard[
|
|
308
|
+
def isCallAttributeNamespace_Identifier(namespace: ast_Identifier, identifier: ast_Identifier) -> Callable[[ast.AST], TypeGuard[ast.Call] | bool]:
|
|
277
309
|
return lambda node: be.Call(node) and 又.func(ifThis.isAttributeNamespace_Identifier(namespace, identifier))(node)
|
|
278
310
|
@staticmethod
|
|
279
|
-
def isName_Identifier(identifier: ast_Identifier) -> Callable[[ast.AST], TypeGuard[
|
|
311
|
+
def isName_Identifier(identifier: ast_Identifier) -> Callable[[ast.AST], TypeGuard[ast.Name] | bool]:
|
|
280
312
|
return lambda node: be.Name(node) and 又.id(ifThis._Identifier(identifier))(node)
|
|
281
313
|
@staticmethod
|
|
282
|
-
def isCall_Identifier(identifier: ast_Identifier) -> Callable[[ast.AST], TypeGuard[
|
|
314
|
+
def isCall_Identifier(identifier: ast_Identifier) -> Callable[[ast.AST], TypeGuard[ast.Call] | bool]:
|
|
283
315
|
return lambda node: be.Call(node) and 又.func(ifThis.isName_Identifier(identifier))(node)
|
|
284
316
|
# ================================================================
|
|
285
317
|
@staticmethod
|
|
318
|
+
def CallDoesNotCallItself(namespace: ast_Identifier, identifier: ast_Identifier) -> Callable[[ast.AST], TypeGuard[ast.Call] | bool]:
|
|
319
|
+
"""If `namespace` is not applicable to your case, then call with `namespace=""`."""
|
|
320
|
+
return lambda node: ifThis.matchesMeButNotAnyDescendant(ifThis.CallReallyIs(namespace, identifier))(node)
|
|
321
|
+
@staticmethod
|
|
286
322
|
def matchesMeButNotAnyDescendant(predicate: Callable[[ast.AST], bool]) -> Callable[[ast.AST], bool]:
|
|
287
323
|
"""Create a predicate that returns True if the node matches but none of its descendants match the predicate."""
|
|
288
324
|
return lambda node: predicate(node) and ifThis.matchesNoDescendant(predicate)(node)
|
|
289
325
|
@staticmethod
|
|
290
326
|
def matchesNoDescendant(predicate: Callable[[ast.AST], bool]) -> Callable[[ast.AST], bool]:
|
|
291
327
|
"""Create a predicate that returns True if no descendant of the node matches the given predicate."""
|
|
292
|
-
def workhorse(node:
|
|
328
|
+
def workhorse(node: TypeCertified) -> bool: # pyright: ignore [reportInvalidTypeVarUse]
|
|
293
329
|
for descendant in ast.walk(node):
|
|
294
330
|
if descendant is not node and predicate(descendant):
|
|
295
331
|
return False
|
|
@@ -297,30 +333,26 @@ Argument of type "typeCertified@isAnnAssign_targetIs" cannot be assigned to para
|
|
|
297
333
|
return workhorse
|
|
298
334
|
|
|
299
335
|
@staticmethod
|
|
300
|
-
def
|
|
301
|
-
"""If `namespace` is not applicable to your case, then call with `namespace=""`."""
|
|
302
|
-
return lambda node: ifThis.matchesMeButNotAnyDescendant(ifThis.CallReallyIs(namespace, identifier))(node)
|
|
303
|
-
@staticmethod
|
|
304
|
-
def CallReallyIs(namespace: ast_Identifier, identifier: ast_Identifier) -> Callable[[ast.AST], TypeGuard[object] | bool]:
|
|
336
|
+
def CallReallyIs(namespace: ast_Identifier, identifier: ast_Identifier) -> Callable[[ast.AST], TypeGuard[ast.Call] | bool]:
|
|
305
337
|
return ifThis.isCall_Identifier(identifier) or ifThis.isCallAttributeNamespace_Identifier(namespace, identifier)
|
|
306
338
|
@staticmethod
|
|
307
|
-
def isAttributeNamespace_Identifier(namespace: ast_Identifier, identifier: ast_Identifier) -> Callable[[ast.AST], TypeGuard[
|
|
339
|
+
def isAttributeNamespace_Identifier(namespace: ast_Identifier, identifier: ast_Identifier) -> Callable[[ast.AST], TypeGuard[ast.Attribute] | bool]:
|
|
308
340
|
return lambda node: ifThis.isAttributeName(node) and 又.value(ifThis.isName_Identifier(namespace))(node) and 又.attr(ifThis._Identifier(identifier))(node)
|
|
309
341
|
@staticmethod
|
|
310
342
|
def _Identifier(identifier: ast_Identifier) -> Callable[[ast_Identifier | None], TypeGuard[ast_Identifier] | bool]:
|
|
311
343
|
return lambda node: node == identifier
|
|
312
344
|
@staticmethod
|
|
313
|
-
def isAttributeName(node:
|
|
345
|
+
def isAttributeName(node: TypeCertified) -> TypeGuard[ast.Attribute]: # pyright: ignore [reportInvalidTypeVarUse]
|
|
314
346
|
""" Displayed as Name.attribute."""
|
|
315
347
|
return be.Attribute(node) and 又.value(be.Name)(node)
|
|
316
348
|
|
|
317
349
|
@staticmethod
|
|
318
|
-
def isCallToName(node:
|
|
350
|
+
def isCallToName(node: TypeCertified) -> TypeGuard[ast.Call]: # pyright: ignore [reportInvalidTypeVarUse]
|
|
319
351
|
return be.Call(node) and 又.func(be.Name)(node)
|
|
320
352
|
@staticmethod
|
|
321
353
|
def ast_IdentifierIn(container: Container[ast_Identifier]) -> Callable[[ast_Identifier], TypeGuard[ast_Identifier] | bool]:
|
|
322
354
|
return lambda node: node in container
|
|
323
355
|
# This bullshit is for the crappy function inliner I made.
|
|
324
356
|
@staticmethod
|
|
325
|
-
def CallDoesNotCallItselfAndNameDOTidIsIn(container: Container[ast_Identifier]) -> Callable[[ast.AST], TypeGuard[
|
|
326
|
-
return lambda node: ifThis.isCallToName(node) and 又.func(又.id(ifThis.ast_IdentifierIn(container)))(node) and ifThis.CallDoesNotCallItself("", node.func.id)(node)
|
|
357
|
+
def CallDoesNotCallItselfAndNameDOTidIsIn(container: Container[ast_Identifier]) -> Callable[[ast.AST], TypeGuard[ast.Call] | bool]:
|
|
358
|
+
return lambda node: ifThis.isCallToName(node) and 又.func(又.id(ifThis.ast_IdentifierIn(container)))(node) and ifThis.CallDoesNotCallItself("", node.func.id)(node) # type: ignore
|
|
@@ -7,8 +7,8 @@ circular imports while providing reusable data structures.
|
|
|
7
7
|
"""
|
|
8
8
|
from collections import defaultdict
|
|
9
9
|
from collections.abc import Sequence
|
|
10
|
-
from mapFolding.someAssemblyRequired import ast_Identifier, be,
|
|
11
|
-
from mapFolding.theSSOT import callableDispatcherHARDCODED,
|
|
10
|
+
from mapFolding.someAssemblyRequired import ImaAnnotationType, ast_Identifier, be, Make, parseLogicalPath2astModule, str_nameDOTname
|
|
11
|
+
from mapFolding.theSSOT import callableDispatcherHARDCODED, The
|
|
12
12
|
from pathlib import Path, PurePosixPath
|
|
13
13
|
from Z0Z_tools import updateExtendPolishDictionaryLists
|
|
14
14
|
import ast
|
|
@@ -299,8 +299,36 @@ theLogicalPathModuleDispatcherSynthetic: str = '.'.join([The.packageName, The.mo
|
|
|
299
299
|
if self.callableDispatcher!=callableDispatcherHARDCODED:
|
|
300
300
|
print(f"fyi: `{self.callableDispatcher=}` but\n\t`{callableDispatcherHARDCODED=}`.")
|
|
301
301
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
302
|
+
dummyAssign = Make.Assign([Make.Name("dummyTarget")], Make.Constant(None))
|
|
303
|
+
dummySubscript = Make.Subscript(Make.Name("dummy"), Make.Name("slice"))
|
|
304
|
+
dummyTuple = Make.Tuple([Make.Name("dummyElement")])
|
|
305
|
+
|
|
306
|
+
@dataclasses.dataclass
|
|
307
|
+
class ShatteredDataclass:
|
|
308
|
+
countingVariableAnnotation: ImaAnnotationType
|
|
309
|
+
"""Type annotation for the counting variable extracted from the dataclass."""
|
|
310
|
+
countingVariableName: ast.Name
|
|
311
|
+
"""AST name node representing the counting variable identifier."""
|
|
312
|
+
field2AnnAssign: dict[ast_Identifier, ast.AnnAssign] = dataclasses.field(default_factory=dict)
|
|
313
|
+
"""Maps field names to their corresponding AST call expressions."""
|
|
314
|
+
Z0Z_field2AnnAssign: dict[ast_Identifier, tuple[ast.AnnAssign, str]] = dataclasses.field(default_factory=dict)
|
|
315
|
+
fragments4AssignmentOrParameters: ast.Tuple = dummyTuple
|
|
316
|
+
"""AST tuple used as target for assignment to capture returned fragments."""
|
|
317
|
+
ledger: LedgerOfImports = dataclasses.field(default_factory=LedgerOfImports)
|
|
318
|
+
"""Import records for the dataclass and its constituent parts."""
|
|
319
|
+
list_argAnnotated4ArgumentsSpecification: list[ast.arg] = dataclasses.field(default_factory=list)
|
|
320
|
+
"""Function argument nodes with annotations for parameter specification."""
|
|
321
|
+
list_keyword_field__field4init: list[ast.keyword] = dataclasses.field(default_factory=list)
|
|
322
|
+
"""Keyword arguments for dataclass initialization with field=field format."""
|
|
323
|
+
listAnnotations: list[ImaAnnotationType] = dataclasses.field(default_factory=list)
|
|
324
|
+
"""Type annotations for each dataclass field."""
|
|
325
|
+
listName4Parameters: list[ast.Name] = dataclasses.field(default_factory=list)
|
|
326
|
+
"""Name nodes for each dataclass field used as function parameters."""
|
|
327
|
+
listUnpack: list[ast.AnnAssign] = dataclasses.field(default_factory=list)
|
|
328
|
+
"""Annotated assignment statements to extract fields from dataclass."""
|
|
329
|
+
map_stateDOTfield2Name: dict[ast.expr, ast.Name] = dataclasses.field(default_factory=dict)
|
|
330
|
+
"""Maps AST expressions to Name nodes for find-replace operations."""
|
|
331
|
+
repack: ast.Assign = dummyAssign
|
|
332
|
+
"""AST assignment statement that reconstructs the original dataclass instance."""
|
|
333
|
+
signatureReturnAnnotation: ast.Subscript = dummySubscript
|
|
334
|
+
"""tuple-based return type annotation for function definitions."""
|
|
@@ -1,57 +1,43 @@
|
|
|
1
|
-
from collections.abc import Callable
|
|
1
|
+
from collections.abc import Callable, Sequence
|
|
2
2
|
from inspect import getsource as inspect_getsource
|
|
3
|
-
from mapFolding.someAssemblyRequired import ast_Identifier, str_nameDOTname
|
|
3
|
+
from mapFolding.someAssemblyRequired import ast_Identifier, str_nameDOTname, 个
|
|
4
4
|
from os import PathLike
|
|
5
5
|
from pathlib import Path, PurePath
|
|
6
6
|
from types import ModuleType
|
|
7
|
-
from typing import Any,
|
|
7
|
+
from typing import Any, cast, Generic, TypeGuard
|
|
8
8
|
import ast
|
|
9
9
|
import importlib
|
|
10
10
|
import importlib.util
|
|
11
11
|
|
|
12
12
|
# TODO Identify the logic that narrows the type and can help the user during static type checking.
|
|
13
13
|
|
|
14
|
-
class NodeTourist(ast.NodeVisitor):
|
|
15
|
-
def __init__(self, findThis, doThat
|
|
14
|
+
class NodeTourist(ast.NodeVisitor, Generic[个]):
|
|
15
|
+
def __init__(self, findThis: Callable[[个], TypeGuard[个] | bool], doThat: Callable[[个], 个 | None]) -> None:
|
|
16
16
|
self.findThis = findThis
|
|
17
17
|
self.doThat = doThat
|
|
18
|
-
self.nodeCaptured = None
|
|
18
|
+
self.nodeCaptured: 个 | None = None
|
|
19
19
|
|
|
20
|
-
def visit(self, node): #
|
|
20
|
+
def visit(self, node: 个) -> None: # pyright: ignore [reportGeneralTypeIssues]
|
|
21
21
|
if self.findThis(node):
|
|
22
|
-
nodeActionReturn = self.doThat(node)
|
|
22
|
+
nodeActionReturn = self.doThat(node)
|
|
23
23
|
if nodeActionReturn is not None:
|
|
24
|
-
self.nodeCaptured = nodeActionReturn
|
|
25
|
-
self.generic_visit(node)
|
|
26
|
-
|
|
27
|
-
def captureLastMatch(self, node): # type: ignore
|
|
28
|
-
"""Capture the last matched node that produces a non-None result.
|
|
29
|
-
|
|
30
|
-
This method traverses the entire tree starting at the given node
|
|
31
|
-
and returns the last non-None value produced by applying doThat
|
|
32
|
-
to a matching node. It will continue traversing after finding a match,
|
|
33
|
-
and the value captured can be replaced by later matches.
|
|
34
|
-
|
|
35
|
-
Parameters:
|
|
36
|
-
node: The AST node to start traversal from
|
|
24
|
+
self.nodeCaptured = nodeActionReturn
|
|
25
|
+
self.generic_visit(cast(ast.AST, node))
|
|
37
26
|
|
|
38
|
-
|
|
39
|
-
The result of applying doThat to the last matching node that returned
|
|
40
|
-
a non-None value, or None if no match found or all matches returned None
|
|
41
|
-
"""
|
|
27
|
+
def captureLastMatch(self, node: 个) -> 个 | None: # pyright: ignore [reportGeneralTypeIssues]
|
|
42
28
|
self.nodeCaptured = None
|
|
43
|
-
self.visit(node)
|
|
29
|
+
self.visit(node)
|
|
44
30
|
return self.nodeCaptured
|
|
45
31
|
|
|
46
|
-
class NodeChanger(ast.NodeTransformer):
|
|
47
|
-
def __init__(self, findThis, doThat
|
|
32
|
+
class NodeChanger(ast.NodeTransformer, Generic[个]):
|
|
33
|
+
def __init__(self, findThis: Callable[[个], bool], doThat: Callable[[个], Sequence[个] | 个 | None]) -> None:
|
|
48
34
|
self.findThis = findThis
|
|
49
35
|
self.doThat = doThat
|
|
50
36
|
|
|
51
|
-
def visit(self, node): #
|
|
37
|
+
def visit(self, node: 个) -> Sequence[个] | 个 | None: # pyright: ignore [reportGeneralTypeIssues]
|
|
52
38
|
if self.findThis(node):
|
|
53
|
-
return self.doThat(node)
|
|
54
|
-
return super().visit(node)
|
|
39
|
+
return self.doThat(node)
|
|
40
|
+
return super().visit(cast(ast.AST, node))
|
|
55
41
|
|
|
56
42
|
def importLogicalPath2Callable(logicalPathModule: str_nameDOTname, identifier: ast_Identifier, packageIdentifierIfRelative: ast_Identifier | None = None) -> Callable[..., Any]:
|
|
57
43
|
moduleImported: ModuleType = importlib.import_module(logicalPathModule, packageIdentifierIfRelative)
|
|
@@ -18,9 +18,9 @@ mapFolding/reference/jobsCompleted/[2x19]/[2x19].ll
|
|
|
18
18
|
|
|
19
19
|
This file demonstrates the low-level optimizations that made this previously
|
|
20
20
|
intractable calculation possible. The IR reveals how the abstract algorithm was
|
|
21
|
-
transformed into efficient machine code through Numba's compilation
|
|
21
|
+
transformed into efficient machine code through Numba's compilation assembly-line.
|
|
22
22
|
|
|
23
|
-
While originally part of a tighter integration with the code generation
|
|
23
|
+
While originally part of a tighter integration with the code generation assembly-line,
|
|
24
24
|
this module now operates as a standalone utility that can be applied to any module
|
|
25
25
|
containing Numba-compiled functions.
|
|
26
26
|
"""
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
from collections.abc import Callable
|
|
2
|
+
from copy import deepcopy
|
|
3
|
+
from mapFolding.someAssemblyRequired import ast_Identifier, RecipeSynthesizeFlow, Then, be, ifThis, DOT, 又, NodeChanger
|
|
4
|
+
from mapFolding.someAssemblyRequired.transformationTools import makeDictionary4InliningFunction, makeDictionaryFunctionDef
|
|
5
|
+
from typing import cast
|
|
6
|
+
import ast
|
|
7
|
+
|
|
8
|
+
def inlineFunctionDef(astFunctionDef: ast.FunctionDef, dictionary4Inlining: dict[ast_Identifier, ast.FunctionDef]) -> ast.FunctionDef:
|
|
9
|
+
|
|
10
|
+
return astFunctionDef
|
|
11
|
+
|
|
12
|
+
# Test code
|
|
13
|
+
testFlow: RecipeSynthesizeFlow = RecipeSynthesizeFlow()
|
|
14
|
+
dictionary4Inlining: dict[ast_Identifier, ast.FunctionDef] = makeDictionary4InliningFunction(
|
|
15
|
+
testFlow.sourceCallableSequential,
|
|
16
|
+
(dictionaryFunctionDef := makeDictionaryFunctionDef(testFlow.source_astModule)))
|
|
17
|
+
|
|
18
|
+
astFunctionDef = dictionaryFunctionDef[testFlow.sourceCallableSequential]
|
|
19
|
+
|
|
20
|
+
astFunctionDefTransformed = inlineFunctionDef(
|
|
21
|
+
astFunctionDef,
|
|
22
|
+
dictionary4Inlining)
|