mapFolding 0.9.5__py3-none-any.whl → 0.11.0__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.
@@ -18,294 +18,16 @@ The containers work in conjunction with transformation tools that manipulate the
18
18
  specific optimizations and transformations.
19
19
  """
20
20
 
21
- from collections import defaultdict
22
- from collections.abc import Callable, Sequence
21
+ from astToolkit import IngredientsFunction as IngredientsFunction, IngredientsModule as IngredientsModule, LedgerOfImports as LedgerOfImports
22
+ from collections.abc import Callable
23
23
  from copy import deepcopy
24
- from typing import Any
25
- from mapFolding.someAssemblyRequired import ast_Identifier, DOT, ifThis, Make, NodeTourist, parseLogicalPath2astModule, str_nameDOTname, Then
24
+ from mapFolding.someAssemblyRequired import ast_Identifier, DOT, IfThis, Make, NodeTourist, parseLogicalPath2astModule, str_nameDOTname, Then
26
25
  from mapFolding.theSSOT import raiseIfNoneGitHubIssueNumber3, The
27
26
  from pathlib import Path, PurePosixPath
28
- from Z0Z_tools import updateExtendPolishDictionaryLists
27
+ from typing import Any, cast
29
28
  import ast
30
29
  import dataclasses
31
30
 
32
- class LedgerOfImports:
33
- """
34
- Track and manage import statements for programmatically generated code.
35
-
36
- LedgerOfImports acts as a registry for import statements, maintaining a clean separation between the logical
37
- structure of imports and their textual representation. It enables:
38
-
39
- 1. Tracking regular imports and import-from statements.
40
- 2. Adding imports programmatically during code transformation.
41
- 3. Merging imports from multiple sources.
42
- 4. Removing unnecessary or conflicting imports.
43
- 5. Generating optimized AST import nodes for the final code.
44
-
45
- This class forms the foundation of dependency management in generated code, ensuring that all required libraries are
46
- available without duplication or conflict.
47
- """
48
- # TODO When resolving the ledger of imports, remove self-referential imports
49
-
50
- def __init__(self, startWith: ast.AST | None = None, type_ignores: list[ast.TypeIgnore] | None = None) -> None:
51
- self.dictionaryImportFrom: dict[str_nameDOTname, list[tuple[ast_Identifier, ast_Identifier | None]]] = defaultdict(list)
52
- self.listImport: list[str_nameDOTname] = []
53
- self.type_ignores = [] if type_ignores is None else list(type_ignores)
54
- if startWith:
55
- self.walkThis(startWith)
56
-
57
- def addAst(self, astImport____: ast.Import | ast.ImportFrom, type_ignores: list[ast.TypeIgnore] | None = None) -> None:
58
- match astImport____:
59
- case ast.Import():
60
- for alias in astImport____.names:
61
- self.listImport.append(alias.name)
62
- case ast.ImportFrom():
63
- # TODO fix the mess created by `None` means '.'. I need a `str_nameDOTname` to replace '.'
64
- if astImport____.module is None:
65
- astImport____.module = '.'
66
- for alias in astImport____.names:
67
- self.dictionaryImportFrom[astImport____.module].append((alias.name, alias.asname))
68
- case _:
69
- raise ValueError(f"I received {type(astImport____) = }, but I can only accept {ast.Import} and {ast.ImportFrom}.")
70
- if type_ignores:
71
- self.type_ignores.extend(type_ignores)
72
-
73
- def addImport_asStr(self, moduleWithLogicalPath: str_nameDOTname, type_ignores: list[ast.TypeIgnore] | None = None) -> None:
74
- self.listImport.append(moduleWithLogicalPath)
75
- if type_ignores:
76
- self.type_ignores.extend(type_ignores)
77
-
78
- def addImportFrom_asStr(self, moduleWithLogicalPath: str_nameDOTname, name: ast_Identifier, asname: ast_Identifier | None = None, type_ignores: list[ast.TypeIgnore] | None = None) -> None:
79
- self.dictionaryImportFrom[moduleWithLogicalPath].append((name, asname))
80
- if type_ignores:
81
- self.type_ignores.extend(type_ignores)
82
-
83
- def removeImportFromModule(self, moduleWithLogicalPath: str_nameDOTname) -> None:
84
- """Remove all imports from a specific module."""
85
- self.removeImportFrom(moduleWithLogicalPath, None, None)
86
-
87
- def removeImportFrom(self, moduleWithLogicalPath: str_nameDOTname, name: ast_Identifier | None, asname: ast_Identifier | None = None) -> None:
88
- """
89
- name, asname Action
90
- None, None : remove all matches for the module
91
- ast_Identifier, ast_Identifier : remove exact matches
92
- ast_Identifier, None : remove exact matches
93
- None, ast_Identifier : remove all matches for asname and if entry_asname is None remove name == ast_Identifier
94
- """
95
- if moduleWithLogicalPath in self.dictionaryImportFrom:
96
- if name is None and asname is None:
97
- # Remove all entries for the module
98
- self.dictionaryImportFrom.pop(moduleWithLogicalPath)
99
- else:
100
- if name is None:
101
- self.dictionaryImportFrom[moduleWithLogicalPath] = [(entry_name, entry_asname) for entry_name, entry_asname in self.dictionaryImportFrom[moduleWithLogicalPath]
102
- if not (entry_asname == asname) and not (entry_asname is None and entry_name == asname)]
103
- else:
104
- self.dictionaryImportFrom[moduleWithLogicalPath] = [(entry_name, entry_asname) for entry_name, entry_asname in self.dictionaryImportFrom[moduleWithLogicalPath]
105
- if not (entry_name == name and entry_asname == asname)]
106
- if not self.dictionaryImportFrom[moduleWithLogicalPath]:
107
- self.dictionaryImportFrom.pop(moduleWithLogicalPath)
108
-
109
- def exportListModuleIdentifiers(self) -> list[ast_Identifier]:
110
- listModuleIdentifiers: list[ast_Identifier] = list(self.dictionaryImportFrom.keys())
111
- listModuleIdentifiers.extend(self.listImport)
112
- return sorted(set(listModuleIdentifiers))
113
-
114
- def makeList_ast(self) -> list[ast.ImportFrom | ast.Import]:
115
- listImportFrom: list[ast.ImportFrom] = []
116
- for moduleWithLogicalPath, listOfNameTuples in sorted(self.dictionaryImportFrom.items()):
117
- listOfNameTuples = sorted(list(set(listOfNameTuples)), key=lambda nameTuple: nameTuple[0])
118
- list_alias: list[ast.alias] = []
119
- for name, asname in listOfNameTuples:
120
- list_alias.append(Make.alias(name, asname))
121
- if list_alias:
122
- listImportFrom.append(Make.ImportFrom(moduleWithLogicalPath, list_alias))
123
- list_astImport: list[ast.Import] = [Make.Import(moduleWithLogicalPath) for moduleWithLogicalPath in sorted(set(self.listImport))]
124
- return listImportFrom + list_astImport
125
-
126
- def update(self, *fromLedger: 'LedgerOfImports') -> None:
127
- """Update this ledger with imports from one or more other ledgers.
128
- Parameters:
129
- *fromLedger: One or more other `LedgerOfImports` objects from which to merge.
130
- """
131
- updatedDictionary = updateExtendPolishDictionaryLists(self.dictionaryImportFrom, *(ledger.dictionaryImportFrom for ledger in fromLedger), destroyDuplicates=True, reorderLists=True)
132
- self.dictionaryImportFrom = defaultdict(list, updatedDictionary)
133
- for ledger in fromLedger:
134
- self.listImport.extend(ledger.listImport)
135
- self.type_ignores.extend(ledger.type_ignores)
136
-
137
- def walkThis(self, walkThis: ast.AST, type_ignores: list[ast.TypeIgnore] | None = None) -> None:
138
- for nodeBuffalo in ast.walk(walkThis):
139
- if isinstance(nodeBuffalo, (ast.Import, ast.ImportFrom)):
140
- self.addAst(nodeBuffalo)
141
- if type_ignores:
142
- self.type_ignores.extend(type_ignores)
143
-
144
- # Consolidate settings classes through inheritance https://github.com/hunterhogan/mapFolding/issues/15
145
- @dataclasses.dataclass
146
- class IngredientsFunction:
147
- """
148
- Package a function definition with its import dependencies for code generation.
149
-
150
- IngredientsFunction encapsulates an AST function definition along with all the imports required for that function to
151
- operate correctly. This creates a modular, portable unit that can be:
152
-
153
- 1. Transformed independently (e.g., by applying Numba decorators).
154
- 2. Transplanted between modules while maintaining dependencies.
155
- 3. Combined with other functions to form complete modules.
156
- 4. Analyzed for optimization opportunities.
157
-
158
- This class forms the primary unit of function manipulation in the code generation system, enabling targeted
159
- transformations while preserving function dependencies.
160
-
161
- Parameters:
162
- astFunctionDef: The AST representation of the function definition
163
- imports: Import statements needed by the function
164
- type_ignores: Type ignore comments associated with the function
165
- """
166
- astFunctionDef: ast.FunctionDef
167
- imports: LedgerOfImports = dataclasses.field(default_factory=LedgerOfImports)
168
- type_ignores: list[ast.TypeIgnore] = dataclasses.field(default_factory=list)
169
-
170
- # Consolidate settings classes through inheritance https://github.com/hunterhogan/mapFolding/issues/15
171
- @dataclasses.dataclass
172
- class IngredientsModule:
173
- """
174
- Assemble a complete Python module from its constituent AST components.
175
-
176
- IngredientsModule provides a structured container for all elements needed to generate a complete Python module,
177
- including:
178
-
179
- 1. Import statements aggregated from all module components.
180
- 2. Prologue code that runs before function definitions.
181
- 3. Function definitions with their dependencies.
182
- 4. Epilogue code that runs after function definitions.
183
- 5. Entry point code executed when the module runs as a script.
184
- 6. Type ignores and other annotations.
185
-
186
- This class enables programmatic assembly of Python modules with a clear separation between different structural
187
- elements, while maintaining the proper ordering and relationships between components.
188
-
189
- The modular design allows transformations to be applied to specific parts of a module while preserving the overall
190
- structure.
191
-
192
- Parameters:
193
- ingredientsFunction (None): One or more `IngredientsFunction` that will appended to `listIngredientsFunctions`.
194
- """
195
- ingredientsFunction: dataclasses.InitVar[Sequence[IngredientsFunction] | IngredientsFunction | None] = None
196
-
197
- # init var with an existing module? method to deconstruct an existing module?
198
-
199
- # `body` attribute of `ast.Module`
200
- """NOTE
201
- - Bare statements in `prologue` and `epilogue` are not 'protected' by `if __name__ == '__main__':` so they will be executed merely by loading the module.
202
- - The dataclass has methods for modifying `prologue`, `epilogue`, and `launcher`.
203
- - However, `prologue`, `epilogue`, and `launcher` are `ast.Module` (as opposed to `list[ast.stmt]`), so that you may use tools such as `ast.walk` and `ast.NodeVisitor` on the fields.
204
- """
205
- imports: LedgerOfImports = dataclasses.field(default_factory=LedgerOfImports)
206
- """Modify this field using the methods in `LedgerOfImports`."""
207
- prologue: ast.Module = Make.Module([],[])
208
- """Statements after the imports and before the functions in listIngredientsFunctions."""
209
- listIngredientsFunctions: list[IngredientsFunction] = dataclasses.field(default_factory=list)
210
- epilogue: ast.Module = Make.Module([],[])
211
- """Statements after the functions in listIngredientsFunctions and before `launcher`."""
212
- launcher: ast.Module = Make.Module([],[])
213
- """`if __name__ == '__main__':`"""
214
-
215
- # `ast.TypeIgnore` statements to supplement those in other fields; `type_ignores` is a parameter for `ast.Module` constructor
216
- supplemental_type_ignores: list[ast.TypeIgnore] = dataclasses.field(default_factory=list)
217
-
218
- def __post_init__(self, ingredientsFunction: Sequence[IngredientsFunction] | IngredientsFunction | None = None) -> None:
219
- if ingredientsFunction is not None:
220
- if isinstance(ingredientsFunction, IngredientsFunction):
221
- self.appendIngredientsFunction(ingredientsFunction)
222
- else:
223
- self.appendIngredientsFunction(*ingredientsFunction)
224
-
225
- def _append_astModule(self, self_astModule: ast.Module, astModule: ast.Module | None, statement: Sequence[ast.stmt] | ast.stmt | None, type_ignores: list[ast.TypeIgnore] | None) -> None:
226
- """Append one or more statements to `prologue`."""
227
- list_body: list[ast.stmt] = []
228
- listTypeIgnore: list[ast.TypeIgnore] = []
229
- if astModule is not None and isinstance(astModule, ast.Module): # type: ignore
230
- list_body.extend(astModule.body)
231
- listTypeIgnore.extend(astModule.type_ignores)
232
- if type_ignores is not None:
233
- listTypeIgnore.extend(type_ignores)
234
- if statement is not None:
235
- if isinstance(statement, Sequence):
236
- list_body.extend(statement)
237
- else:
238
- list_body.append(statement)
239
- self_astModule.body.extend(list_body)
240
- self_astModule.type_ignores.extend(listTypeIgnore)
241
- ast.fix_missing_locations(self_astModule)
242
-
243
- def appendPrologue(self, astModule: ast.Module | None = None, statement: Sequence[ast.stmt] | ast.stmt | None = None, type_ignores: list[ast.TypeIgnore] | None = None) -> None:
244
- """Append one or more statements to `prologue`."""
245
- self._append_astModule(self.prologue, astModule, statement, type_ignores)
246
-
247
- def appendEpilogue(self, astModule: ast.Module | None = None, statement: Sequence[ast.stmt] | ast.stmt | None = None, type_ignores: list[ast.TypeIgnore] | None = None) -> None:
248
- """Append one or more statements to `epilogue`."""
249
- self._append_astModule(self.epilogue, astModule, statement, type_ignores)
250
-
251
- def appendLauncher(self, astModule: ast.Module | None = None, statement: Sequence[ast.stmt] | ast.stmt | None = None, type_ignores: list[ast.TypeIgnore] | None = None) -> None:
252
- """Append one or more statements to `launcher`."""
253
- self._append_astModule(self.launcher, astModule, statement, type_ignores)
254
-
255
- def appendIngredientsFunction(self, *ingredientsFunction: IngredientsFunction) -> None:
256
- """Append one or more `IngredientsFunction`."""
257
- for allegedIngredientsFunction in ingredientsFunction:
258
- self.listIngredientsFunctions.append(allegedIngredientsFunction)
259
-
260
- def removeImportFromModule(self, moduleWithLogicalPath: str_nameDOTname) -> None:
261
- self.removeImportFrom(moduleWithLogicalPath, None, None)
262
- """Remove all imports from a specific module."""
263
-
264
- def removeImportFrom(self, moduleWithLogicalPath: str_nameDOTname, name: ast_Identifier | None, asname: ast_Identifier | None = None) -> None:
265
- """
266
- This method modifies all `LedgerOfImports` in this `IngredientsModule` and all `IngredientsFunction` in `listIngredientsFunctions`.
267
- It is not a "blacklist", so the `import from` could be added after this modification.
268
- """
269
- self.imports.removeImportFrom(moduleWithLogicalPath, name, asname)
270
- for ingredientsFunction in self.listIngredientsFunctions:
271
- ingredientsFunction.imports.removeImportFrom(moduleWithLogicalPath, name, asname)
272
-
273
- def _consolidatedLedger(self) -> LedgerOfImports:
274
- """Consolidate all ledgers of imports."""
275
- sherpaLedger = LedgerOfImports()
276
- listLedgers: list[LedgerOfImports] = [self.imports]
277
- for ingredientsFunction in self.listIngredientsFunctions:
278
- listLedgers.append(ingredientsFunction.imports)
279
- sherpaLedger.update(*listLedgers)
280
- return sherpaLedger
281
-
282
- @property
283
- def list_astImportImportFrom(self) -> list[ast.Import | ast.ImportFrom]:
284
- return self._consolidatedLedger().makeList_ast()
285
-
286
- @property
287
- def body(self) -> list[ast.stmt]:
288
- list_stmt: list[ast.stmt] = []
289
- list_stmt.extend(self.list_astImportImportFrom)
290
- list_stmt.extend(self.prologue.body)
291
- for ingredientsFunction in self.listIngredientsFunctions:
292
- list_stmt.append(ingredientsFunction.astFunctionDef)
293
- list_stmt.extend(self.epilogue.body)
294
- list_stmt.extend(self.launcher.body)
295
- # TODO `launcher`, if it exists, must start with `if __name__ == '__main__':` and be indented
296
- return list_stmt
297
-
298
- @property
299
- def type_ignores(self) -> list[ast.TypeIgnore]:
300
- listTypeIgnore: list[ast.TypeIgnore] = self.supplemental_type_ignores
301
- listTypeIgnore.extend(self._consolidatedLedger().type_ignores)
302
- listTypeIgnore.extend(self.prologue.type_ignores)
303
- for ingredientsFunction in self.listIngredientsFunctions:
304
- listTypeIgnore.extend(ingredientsFunction.type_ignores)
305
- listTypeIgnore.extend(self.epilogue.type_ignores)
306
- listTypeIgnore.extend(self.launcher.type_ignores)
307
- return listTypeIgnore
308
-
309
31
  # Consolidate settings classes through inheritance https://github.com/hunterhogan/mapFolding/issues/15
310
32
  @dataclasses.dataclass
311
33
  class RecipeSynthesizeFlow:
@@ -531,7 +253,13 @@ class DeReConstructField2ast:
531
253
  self.ast_keyword_field__field = Make.keyword(self.name, self.astName)
532
254
  self.ast_nameDOTname = Make.Attribute(Make.Name(dataclassesDOTdataclassInstance_Identifier), self.name)
533
255
 
534
- sherpa = NodeTourist(ifThis.isAnnAssign_targetIs(ifThis.isName_Identifier(self.name)), Then.extractIt(DOT.annotation)).captureLastMatch(dataclassClassDef)
256
+ findThis = IfThis.isAnnAssign_targetIs(IfThis.isName_Identifier(self.name))
257
+
258
+ sherpa = NodeTourist(
259
+ findThis=findThis
260
+ , doThat=Then.extractIt(DOT.annotation)
261
+ ).captureLastMatch(dataclassClassDef)
262
+
535
263
  if sherpa is None: raise raiseIfNoneGitHubIssueNumber3
536
264
  else: self.astAnnotation = sherpa
537
265
 
@@ -544,7 +272,7 @@ class DeReConstructField2ast:
544
272
  self.ledger.addImportFrom_asStr(moduleWithLogicalPath, annotationType)
545
273
  self.ledger.addImportFrom_asStr(moduleWithLogicalPath, 'dtype')
546
274
  axesSubscript = Make.Subscript(Make.Name('tuple'), Make.Name('uint8'))
547
- dtype_asnameName: ast.Name = self.astAnnotation # type: ignore
275
+ dtype_asnameName: ast.Name = cast(ast.Name, self.astAnnotation)
548
276
  if dtype_asnameName.id == 'Array3D':
549
277
  axesSubscript = Make.Subscript(Make.Name('tuple'), Make.Tuple([Make.Name('uint8'), Make.Name('uint8'), Make.Name('uint8')]))
550
278
  ast_expr = Make.Subscript(Make.Name(annotationType), Make.Tuple([axesSubscript, Make.Subscript(Make.Name('dtype'), dtype_asnameName)]))
@@ -552,8 +280,8 @@ class DeReConstructField2ast:
552
280
  self.ledger.addImportFrom_asStr(moduleWithLogicalPath, constructor)
553
281
  dtypeIdentifier: ast_Identifier = dtype.__name__
554
282
  self.ledger.addImportFrom_asStr(moduleWithLogicalPath, dtypeIdentifier, dtype_asnameName.id)
555
- self.astAnnAssignConstructor = Make.AnnAssign(self.astName, ast_expr, Make.Call(Make.Name(constructor), list_astKeywords=[Make.keyword('dtype', dtype_asnameName)]))
556
- self.astAnnAssignConstructor = Make.Assign([self.astName], Make.Call(Make.Name(constructor), list_astKeywords=[Make.keyword('dtype', dtype_asnameName)]))
283
+ self.astAnnAssignConstructor = Make.AnnAssign(self.astName, ast_expr, Make.Call(Make.Name(constructor), list_keyword=[Make.keyword('dtype', dtype_asnameName)]))
284
+ self.astAnnAssignConstructor = Make.Assign([self.astName], Make.Call(Make.Name(constructor), list_keyword=[Make.keyword('dtype', dtype_asnameName)]))
557
285
  self.Z0Z_hack = (self.astAnnAssignConstructor, 'array')
558
286
  elif isinstance(self.astAnnotation, ast.Name):
559
287
  self.astAnnAssignConstructor = Make.AnnAssign(self.astName, self.astAnnotation, Make.Call(self.astAnnotation, [Make.Constant(-1)]))
@@ -561,7 +289,7 @@ class DeReConstructField2ast:
561
289
  elif isinstance(self.astAnnotation, ast.Subscript):
562
290
  elementConstructor: ast_Identifier = self.metadata['elementConstructor']
563
291
  self.ledger.addImportFrom_asStr(dataclassesDOTdataclassLogicalPathModule, elementConstructor)
564
- takeTheTuple: ast.Tuple = deepcopy(self.astAnnotation.slice) # type: ignore
292
+ takeTheTuple = deepcopy(self.astAnnotation.slice)
565
293
  self.astAnnAssignConstructor = Make.AnnAssign(self.astName, self.astAnnotation, takeTheTuple)
566
294
  self.Z0Z_hack = (self.astAnnAssignConstructor, elementConstructor)
567
295
  if isinstance(self.astAnnotation, ast.Name):
@@ -1,9 +1,9 @@
1
1
  from mapFolding import getPathFilenameFoldsTotal, raiseIfNoneGitHubIssueNumber3, The
2
2
  from mapFolding.someAssemblyRequired import (
3
3
  ast_Identifier,
4
- be,
4
+ Be,
5
5
  extractFunctionDef,
6
- ifThis,
6
+ IfThis,
7
7
  IngredientsFunction,
8
8
  IngredientsModule,
9
9
  LedgerOfImports,
@@ -15,7 +15,7 @@ from mapFolding.someAssemblyRequired import (
15
15
  )
16
16
  from mapFolding.someAssemblyRequired.RecipeJob import RecipeJobTheorem2Numba
17
17
  from mapFolding.someAssemblyRequired.toolboxNumba import parametersNumbaLight, SpicesJobNumba, decorateCallableWithNumba
18
- from mapFolding.someAssemblyRequired.transformationTools import dictionaryEstimates, write_astModule, makeInitializedComputationState
18
+ from mapFolding.someAssemblyRequired.transformationTools import write_astModule
19
19
  from mapFolding.syntheticModules.initializeCount import initializeGroupsOfFolds
20
20
  from mapFolding.dataBaskets import MapFoldingState
21
21
  from pathlib import PurePosixPath
@@ -77,12 +77,12 @@ if __name__ == '__main__':
77
77
  ast_argNumbaProgress = ast.arg(arg=spices.numbaProgressBarIdentifier, annotation=ast.Name(id=numba_progressPythonClass, ctx=ast.Load()))
78
78
  ingredientsFunction.astFunctionDef.args.args.append(ast_argNumbaProgress)
79
79
 
80
- findThis = ifThis.isAugAssign_targetIs(ifThis.isName_Identifier(job.shatteredDataclass.countingVariableName.id))
80
+ findThis = IfThis.isAugAssignAndTargetIs(IfThis.isName_Identifier(job.shatteredDataclass.countingVariableName.id))
81
81
  doThat = Then.replaceWith(Make.Expr(Make.Call(Make.Attribute(Make.Name(spices.numbaProgressBarIdentifier),'update'),[Make.Constant(1)])))
82
82
  countWithProgressBar = NodeChanger(findThis, doThat)
83
83
  countWithProgressBar.visit(ingredientsFunction.astFunctionDef)
84
84
 
85
- removeReturnStatement = NodeChanger(be.Return, Then.removeIt)
85
+ removeReturnStatement = NodeChanger(Be.Return, Then.removeIt)
86
86
  removeReturnStatement.visit(ingredientsFunction.astFunctionDef)
87
87
  ingredientsFunction.astFunctionDef.returns = Make.Constant(value=None)
88
88
 
@@ -119,7 +119,7 @@ def move_arg2FunctionDefDOTbodyAndAssignInitialValues(ingredientsFunction: Ingre
119
119
  list_argCuzMyBrainRefusesToThink = ingredientsFunction.astFunctionDef.args.args + ingredientsFunction.astFunctionDef.args.posonlyargs + ingredientsFunction.astFunctionDef.args.kwonlyargs
120
120
  list_arg_arg: list[ast_Identifier] = [ast_arg.arg for ast_arg in list_argCuzMyBrainRefusesToThink]
121
121
  listName: list[ast.Name] = []
122
- NodeTourist(be.Name, Then.appendTo(listName)).visit(ingredientsFunction.astFunctionDef)
122
+ NodeTourist(Be.Name, Then.appendTo(listName)).visit(ingredientsFunction.astFunctionDef)
123
123
  list_Identifiers: list[ast_Identifier] = [astName.id for astName in listName]
124
124
  list_IdentifiersNotUsed: list[ast_Identifier] = list(set(list_arg_arg) - set(list_Identifiers))
125
125
 
@@ -131,23 +131,23 @@ def move_arg2FunctionDefDOTbodyAndAssignInitialValues(ingredientsFunction: Ingre
131
131
  ImaAnnAssign, elementConstructor = job.shatteredDataclass.Z0Z_field2AnnAssign[ast_arg.arg]
132
132
  match elementConstructor:
133
133
  case 'scalar':
134
- ImaAnnAssign.value.args[0].value = int(job.state.__dict__[ast_arg.arg]) # type: ignore
134
+ cast(ast.Constant, cast(ast.Call, ImaAnnAssign.value).args[0]).value = int(job.state.__dict__[ast_arg.arg])
135
135
  case 'array':
136
136
  dataAsStrRLE: str = autoDecodingRLE(job.state.__dict__[ast_arg.arg], True)
137
137
  dataAs_astExpr: ast.expr = cast(ast.Expr, ast.parse(dataAsStrRLE).body[0]).value
138
- ImaAnnAssign.value.args = [dataAs_astExpr] # type: ignore
138
+ cast(ast.Call, ImaAnnAssign.value).args = [dataAs_astExpr]
139
139
  case _:
140
140
  list_exprDOTannotation: list[ast.expr] = []
141
141
  list_exprDOTvalue: list[ast.expr] = []
142
142
  for dimension in job.state.mapShape:
143
143
  list_exprDOTannotation.append(Make.Name(elementConstructor))
144
144
  list_exprDOTvalue.append(Make.Call(Make.Name(elementConstructor), [Make.Constant(dimension)]))
145
- ImaAnnAssign.annotation.slice.elts = list_exprDOTannotation # type: ignore
146
- ImaAnnAssign.value.elts = list_exprDOTvalue # type: ignore
145
+ cast(ast.Tuple, cast(ast.Subscript, cast(ast.AnnAssign, ImaAnnAssign).annotation).slice).elts = list_exprDOTannotation
146
+ cast(ast.Tuple, ImaAnnAssign.value).elts = list_exprDOTvalue
147
147
 
148
148
  ingredientsFunction.astFunctionDef.body.insert(0, ImaAnnAssign)
149
149
 
150
- findThis = ifThis.is_arg_Identifier(ast_arg.arg)
150
+ findThis = IfThis.is_arg_Identifier(ast_arg.arg)
151
151
  remove_arg = NodeChanger(findThis, Then.removeIt)
152
152
  remove_arg.visit(ingredientsFunction.astFunctionDef)
153
153
 
@@ -161,7 +161,7 @@ def makeJobNumba(job: RecipeJobTheorem2Numba, spices: SpicesJobNumba) -> None:
161
161
  ingredientsCount: IngredientsFunction = IngredientsFunction(astFunctionDef, LedgerOfImports())
162
162
 
163
163
  # Remove `foldGroups` and any other unused statements, so you can dynamically determine which variables are not used
164
- findThis = ifThis.isAssignAndTargets0Is(ifThis.isSubscript_Identifier('foldGroups'))
164
+ findThis = IfThis.isAssignAndTargets0Is(IfThis.isSubscript_Identifier('foldGroups'))
165
165
  doThat = Then.removeIt
166
166
  remove_foldGroups = NodeChanger(findThis, doThat)
167
167
  remove_foldGroups.visit(ingredientsCount.astFunctionDef)
@@ -169,7 +169,7 @@ def makeJobNumba(job: RecipeJobTheorem2Numba, spices: SpicesJobNumba) -> None:
169
169
  # replace identifiers with static values with their values, so you can dynamically determine which variables are not used
170
170
  list_IdentifiersStaticValues = list_IdentifiersStaticValuesHARDCODED
171
171
  for identifier in list_IdentifiersStaticValues:
172
- findThis = ifThis.isName_Identifier(identifier)
172
+ findThis = IfThis.isName_Identifier(identifier)
173
173
  doThat = Then.replaceWith(Make.Constant(int(job.state.__dict__[identifier])))
174
174
  NodeChanger(findThis, doThat).visit(ingredientsCount.astFunctionDef)
175
175
 
@@ -193,7 +193,7 @@ if __name__ == '__main__':
193
193
  # from mapFolding.oeis import getFoldsTotalKnown
194
194
  # print(foldsTotal == getFoldsTotalKnown({job.state.mapShape}))
195
195
  ingredientsModule.appendLauncher(ast.parse(linesLaunch))
196
- changeReturnParallelCallable = NodeChanger(be.Return, Then.replaceWith(Make.Return(job.shatteredDataclass.countingVariableName)))
196
+ changeReturnParallelCallable = NodeChanger(Be.Return, Then.replaceWith(Make.Return(job.shatteredDataclass.countingVariableName)))
197
197
  changeReturnParallelCallable.visit(ingredientsCount.astFunctionDef)
198
198
  ingredientsCount.astFunctionDef.returns = job.shatteredDataclass.countingVariableAnnotation
199
199
 
@@ -21,9 +21,9 @@ as Python scripts or further compiled into standalone executables.
21
21
  from mapFolding import getPathFilenameFoldsTotal, raiseIfNoneGitHubIssueNumber3, The
22
22
  from mapFolding.someAssemblyRequired import (
23
23
  ast_Identifier,
24
- be,
24
+ Be,
25
25
  extractFunctionDef,
26
- ifThis,
26
+ IfThis,
27
27
  IngredientsFunction,
28
28
  IngredientsModule,
29
29
  LedgerOfImports,
@@ -95,12 +95,12 @@ if __name__ == '__main__':
95
95
  ast_argNumbaProgress = ast.arg(arg=spices.numbaProgressBarIdentifier, annotation=ast.Name(id=numba_progressPythonClass, ctx=ast.Load()))
96
96
  ingredientsFunction.astFunctionDef.args.args.append(ast_argNumbaProgress)
97
97
 
98
- findThis = ifThis.isAugAssign_targetIs(ifThis.isName_Identifier(job.shatteredDataclass.countingVariableName.id))
98
+ findThis = IfThis.isAugAssignAndTargetIs(IfThis.isName_Identifier(job.shatteredDataclass.countingVariableName.id))
99
99
  doThat = Then.replaceWith(Make.Expr(Make.Call(Make.Attribute(Make.Name(spices.numbaProgressBarIdentifier),'update'),[Make.Constant(1)])))
100
100
  countWithProgressBar = NodeChanger(findThis, doThat)
101
101
  countWithProgressBar.visit(ingredientsFunction.astFunctionDef)
102
102
 
103
- removeReturnStatement = NodeChanger(be.Return, Then.removeIt)
103
+ removeReturnStatement = NodeChanger(Be.Return, Then.removeIt)
104
104
  removeReturnStatement.visit(ingredientsFunction.astFunctionDef)
105
105
  ingredientsFunction.astFunctionDef.returns = Make.Constant(value=None)
106
106
 
@@ -137,7 +137,7 @@ def move_arg2FunctionDefDOTbodyAndAssignInitialValues(ingredientsFunction: Ingre
137
137
  list_argCuzMyBrainRefusesToThink = ingredientsFunction.astFunctionDef.args.args + ingredientsFunction.astFunctionDef.args.posonlyargs + ingredientsFunction.astFunctionDef.args.kwonlyargs
138
138
  list_arg_arg: list[ast_Identifier] = [ast_arg.arg for ast_arg in list_argCuzMyBrainRefusesToThink]
139
139
  listName: list[ast.Name] = []
140
- NodeTourist(be.Name, Then.appendTo(listName)).visit(ingredientsFunction.astFunctionDef)
140
+ NodeTourist(Be.Name, Then.appendTo(listName)).visit(ingredientsFunction.astFunctionDef)
141
141
  list_Identifiers: list[ast_Identifier] = [astName.id for astName in listName]
142
142
  list_IdentifiersNotUsed: list[ast_Identifier] = list(set(list_arg_arg) - set(list_Identifiers))
143
143
 
@@ -149,23 +149,23 @@ def move_arg2FunctionDefDOTbodyAndAssignInitialValues(ingredientsFunction: Ingre
149
149
  ImaAnnAssign, elementConstructor = job.shatteredDataclass.Z0Z_field2AnnAssign[ast_arg.arg]
150
150
  match elementConstructor:
151
151
  case 'scalar':
152
- ImaAnnAssign.value.args[0].value = int(job.state.__dict__[ast_arg.arg]) # type: ignore
152
+ cast(ast.Constant, cast(ast.Call, ImaAnnAssign.value).args[0]).value = int(job.state.__dict__[ast_arg.arg])
153
153
  case 'array':
154
154
  dataAsStrRLE: str = autoDecodingRLE(job.state.__dict__[ast_arg.arg], True)
155
155
  dataAs_astExpr: ast.expr = cast(ast.Expr, ast.parse(dataAsStrRLE).body[0]).value
156
- ImaAnnAssign.value.args = [dataAs_astExpr] # type: ignore
156
+ cast(ast.Call, ImaAnnAssign.value).args = [dataAs_astExpr]
157
157
  case _:
158
158
  list_exprDOTannotation: list[ast.expr] = []
159
159
  list_exprDOTvalue: list[ast.expr] = []
160
160
  for dimension in job.state.mapShape:
161
161
  list_exprDOTannotation.append(Make.Name(elementConstructor))
162
162
  list_exprDOTvalue.append(Make.Call(Make.Name(elementConstructor), [Make.Constant(dimension)]))
163
- ImaAnnAssign.annotation.slice.elts = list_exprDOTannotation # type: ignore
164
- ImaAnnAssign.value.elts = list_exprDOTvalue # type: ignore
163
+ cast(ast.Tuple, cast(ast.Subscript, cast(ast.AnnAssign, ImaAnnAssign).annotation).slice).elts = list_exprDOTannotation
164
+ cast(ast.Tuple, ImaAnnAssign.value).elts = list_exprDOTvalue
165
165
 
166
166
  ingredientsFunction.astFunctionDef.body.insert(0, ImaAnnAssign)
167
167
 
168
- findThis = ifThis.is_arg_Identifier(ast_arg.arg)
168
+ findThis = IfThis.is_arg_Identifier(ast_arg.arg)
169
169
  remove_arg = NodeChanger(findThis, Then.removeIt)
170
170
  remove_arg.visit(ingredientsFunction.astFunctionDef)
171
171
 
@@ -201,7 +201,7 @@ def makeJobNumba(job: RecipeJob, spices: SpicesJobNumba) -> None:
201
201
  ingredientsCount: IngredientsFunction = IngredientsFunction(astFunctionDef, LedgerOfImports())
202
202
 
203
203
  # Remove `foldGroups` and any other unused statements, so you can dynamically determine which variables are not used
204
- findThis = ifThis.isAssignAndTargets0Is(ifThis.isSubscript_Identifier('foldGroups'))
204
+ findThis = IfThis.isAssignAndTargets0Is(IfThis.isSubscript_Identifier('foldGroups'))
205
205
  doThat = Then.removeIt
206
206
  remove_foldGroups = NodeChanger(findThis, doThat)
207
207
  remove_foldGroups.visit(ingredientsCount.astFunctionDef)
@@ -209,7 +209,7 @@ def makeJobNumba(job: RecipeJob, spices: SpicesJobNumba) -> None:
209
209
  # replace identifiers with static values with their values, so you can dynamically determine which variables are not used
210
210
  list_IdentifiersStaticValues = list_IdentifiersStaticValuesHARDCODED
211
211
  for identifier in list_IdentifiersStaticValues:
212
- findThis = ifThis.isName_Identifier(identifier)
212
+ findThis = IfThis.isName_Identifier(identifier)
213
213
  doThat = Then.replaceWith(Make.Constant(int(job.state.__dict__[identifier])))
214
214
  NodeChanger(findThis, doThat).visit(ingredientsCount.astFunctionDef)
215
215
 
@@ -233,7 +233,7 @@ if __name__ == '__main__':
233
233
  # from mapFolding.oeis import getFoldsTotalKnown
234
234
  # print(foldsTotal == getFoldsTotalKnown({job.state.mapShape}))
235
235
  ingredientsModule.appendLauncher(ast.parse(linesLaunch))
236
- changeReturnParallelCallable = NodeChanger(be.Return, Then.replaceWith(Make.Return(job.shatteredDataclass.countingVariableName)))
236
+ changeReturnParallelCallable = NodeChanger(Be.Return, Then.replaceWith(Make.Return(job.shatteredDataclass.countingVariableName)))
237
237
  changeReturnParallelCallable.visit(ingredientsCount.astFunctionDef)
238
238
  ingredientsCount.astFunctionDef.returns = job.shatteredDataclass.countingVariableAnnotation
239
239
 
@@ -123,7 +123,7 @@ def decorateCallableWithNumba(ingredientsFunction: IngredientsFunction, paramete
123
123
  ingredientsFunction.imports.addImportFrom_asStr(decoratorModule, decoratorCallable)
124
124
  # Leave this line in so that global edits will change it.
125
125
  astDecorator: ast.Call = Make.Call(Make.Name(decoratorCallable), list_argsDecorator, listDecoratorKeywords)
126
- astDecorator: ast.Call = Make.Call(Make.Name(decoratorCallable), list_astKeywords=listDecoratorKeywords)
126
+ astDecorator: ast.Call = Make.Call(Make.Name(decoratorCallable), list_keyword=listDecoratorKeywords)
127
127
 
128
128
  ingredientsFunction.astFunctionDef.decorator_list = [astDecorator]
129
129
  return ingredientsFunction