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.
mapFolding/__init__.py CHANGED
@@ -47,38 +47,39 @@ foundation for exploring advanced code transformation techniques.
47
47
  from typing import Any, TypeAlias
48
48
  import sys
49
49
 
50
- stuPyd: TypeAlias = Any
51
-
52
- if sys.version_info >= (3, 12):
53
- from ast import (
54
- ParamSpec as astDOTParamSpec,
55
- type_param as astDOTtype_param,
56
- TypeAlias as astDOTTypeAlias,
57
- TypeVar as astDOTTypeVar,
58
- TypeVarTuple as astDOTTypeVarTuple,
59
- )
60
- else:
61
- astDOTParamSpec: TypeAlias = stuPyd
62
- astDOTtype_param: TypeAlias = stuPyd
63
- astDOTTypeAlias: TypeAlias = stuPyd
64
- astDOTTypeVar: TypeAlias = stuPyd
65
- astDOTTypeVarTuple: TypeAlias = stuPyd
50
+ yourPythonIsOld: TypeAlias = Any
51
+ # ruff: noqa: E402
52
+
53
+ # if sys.version_info >= (3, 12):
54
+ # from ast import (
55
+ # ParamSpec as astDOTParamSpec,
56
+ # type_param as astDOTtype_param,
57
+ # TypeAlias as astDOTTypeAlias,
58
+ # TypeVar as astDOTTypeVar,
59
+ # TypeVarTuple as astDOTTypeVarTuple,
60
+ # )
61
+ # else:
62
+ # astDOTParamSpec: TypeAlias = yourPythonIsOld
63
+ # astDOTtype_param: TypeAlias = yourPythonIsOld
64
+ # astDOTTypeAlias: TypeAlias = yourPythonIsOld
65
+ # astDOTTypeVar: TypeAlias = yourPythonIsOld
66
+ # astDOTTypeVarTuple: TypeAlias = yourPythonIsOld
66
67
 
67
68
  if sys.version_info >= (3, 11):
68
- from ast import TryStar as astDOTTryStar
69
+ # from ast import TryStar as astDOTTryStar
69
70
  from typing import TypedDict as TypedDict
70
71
  from typing import NotRequired as NotRequired
71
72
  else:
72
- astDOTTryStar: TypeAlias = stuPyd
73
+ astDOTTryStar: TypeAlias = yourPythonIsOld
73
74
  try:
74
75
  from typing_extensions import TypedDict as TypedDict
75
76
  from typing_extensions import NotRequired as NotRequired
76
77
  except Exception:
77
- TypedDict = dict[stuPyd, stuPyd]
78
+ TypedDict = dict[yourPythonIsOld, yourPythonIsOld]
78
79
  from collections.abc import Iterable
79
80
  NotRequired: TypeAlias = Iterable
80
81
 
81
- from mapFolding.datatypes import ( # noqa: E402
82
+ from mapFolding.datatypes import (
82
83
  Array1DElephino as Array1DElephino,
83
84
  Array1DFoldsTotal as Array1DFoldsTotal,
84
85
  Array1DLeavesTotal as Array1DLeavesTotal,
@@ -92,18 +93,18 @@ from mapFolding.datatypes import ( # noqa: E402
92
93
  NumPyLeavesTotal as NumPyLeavesTotal,
93
94
  )
94
95
 
95
- from mapFolding.theSSOT import ( # noqa: E402
96
+ from mapFolding.theSSOT import (
96
97
  ComputationState as ComputationState,
97
98
  raiseIfNoneGitHubIssueNumber3 as raiseIfNoneGitHubIssueNumber3,
98
99
  The as The,
99
100
  )
100
101
 
101
- from mapFolding.theDao import ( # noqa: E402
102
+ from mapFolding.theDao import (
102
103
  countInitialize as countInitialize,
103
104
  doTheNeedful as doTheNeedful,
104
105
  )
105
106
 
106
- from mapFolding.beDRY import ( # noqa: E402
107
+ from mapFolding.beDRY import (
107
108
  getLeavesTotal as getLeavesTotal,
108
109
  getTaskDivisions as getTaskDivisions,
109
110
  outfitCountFolds as outfitCountFolds,
@@ -111,17 +112,18 @@ from mapFolding.beDRY import ( # noqa: E402
111
112
  validateListDimensions as validateListDimensions,
112
113
  )
113
114
 
114
- from mapFolding.toolboxFilesystem import ( # noqa: E402
115
+ from mapFolding.toolboxFilesystem import (
115
116
  getPathFilenameFoldsTotal as getPathFilenameFoldsTotal,
116
117
  getPathRootJobDEFAULT as getPathRootJobDEFAULT,
117
118
  saveFoldsTotal as saveFoldsTotal,
118
119
  saveFoldsTotalFAILearly as saveFoldsTotalFAILearly,
119
- writeStringToHere as writeStringToHere,
120
120
  )
121
121
 
122
- from mapFolding.basecamp import countFolds as countFolds # noqa: E402
122
+ from Z0Z_tools import writeStringToHere as writeStringToHere
123
+
124
+ from mapFolding.basecamp import countFolds as countFolds
123
125
 
124
- from mapFolding.oeis import ( # noqa: E402
126
+ from mapFolding.oeis import (
125
127
  clearOEIScache as clearOEIScache,
126
128
  getFoldsTotalKnown as getFoldsTotalKnown,
127
129
  getOEISids as getOEISids,
@@ -2,11 +2,11 @@ from mapFolding import raiseIfNoneGitHubIssueNumber3, The
2
2
  from mapFolding.someAssemblyRequired import (
3
3
  ast_Identifier,
4
4
  astModuleToIngredientsFunction,
5
- be,
5
+ Be,
6
6
  DOT,
7
7
  extractFunctionDef,
8
- grab,
9
- ifThis,
8
+ Grab,
9
+ IfThis,
10
10
  IngredientsFunction,
11
11
  IngredientsModule,
12
12
  LedgerOfImports,
@@ -26,7 +26,7 @@ from mapFolding.someAssemblyRequired.transformationTools import (
26
26
  shatter_dataclassesDOTdataclass,
27
27
  unpackDataclassCallFunctionRepackDataclass,
28
28
  write_astModule,
29
- )
29
+ )
30
30
  from pathlib import PurePath
31
31
  import ast
32
32
 
@@ -35,7 +35,7 @@ sourceCallableIdentifierHARDCODED = 'count'
35
35
  logicalPathInfixHARDCODED: ast_Identifier = 'syntheticModules'
36
36
  theCountingIdentifierHARDCODED: ast_Identifier = 'groupsOfFolds'
37
37
 
38
- def makeInitializeGroupsOfFolds():
38
+ def makeInitializeGroupsOfFolds() -> None:
39
39
  callableIdentifierHARDCODED = 'initializeGroupsOfFolds'
40
40
  moduleIdentifierHARDCODED: ast_Identifier = 'initializeCount'
41
41
 
@@ -53,15 +53,12 @@ def makeInitializeGroupsOfFolds():
53
53
 
54
54
  countInitializeIngredients.astFunctionDef.name = callableIdentifier
55
55
 
56
- dataclassInstanceIdentifier = NodeTourist(be.arg, Then.extractIt(DOT.arg)).captureLastMatch(countInitializeIngredients.astFunctionDef)
56
+ dataclassInstanceIdentifier = NodeTourist(Be.arg, Then.extractIt(DOT.arg)).captureLastMatch(countInitializeIngredients.astFunctionDef)
57
57
  if dataclassInstanceIdentifier is None: raise raiseIfNoneGitHubIssueNumber3
58
58
  theCountingIdentifier = theCountingIdentifierHARDCODED
59
59
 
60
- findThis = ifThis.isWhileAttributeNamespace_IdentifierGreaterThan0(dataclassInstanceIdentifier, 'leaf1ndex')
61
- doThat = grab.testAttribute(grab.andDoAllOf([
62
- grab.opsAttribute(Then.replaceWith([ast.Eq()])), # type: ignore
63
- grab.leftAttribute(grab.attrAttribute(Then.replaceWith(theCountingIdentifier))) # type: ignore
64
- ]))
60
+ findThis = IfThis.isWhileAttributeNamespace_IdentifierGreaterThan0(dataclassInstanceIdentifier, 'leaf1ndex')
61
+ doThat = Grab.testAttribute(Grab.andDoAllOf([ Grab.opsAttribute(Then.replaceWith([ast.Eq()])), Grab.leftAttribute(Grab.attrAttribute(Then.replaceWith(theCountingIdentifier))) ])) # type: ignore
65
62
  NodeChanger(findThis, doThat).visit(countInitializeIngredients.astFunctionDef.body[0])
66
63
 
67
64
  ingredientsModule = IngredientsModule(countInitializeIngredients)
@@ -70,7 +67,7 @@ def makeInitializeGroupsOfFolds():
70
67
 
71
68
  write_astModule(ingredientsModule, pathFilename, The.packageName)
72
69
 
73
- def makeDaoOfMapFolding():
70
+ def makeDaoOfMapFolding() -> PurePath:
74
71
  moduleIdentifierHARDCODED: ast_Identifier = 'daoOfMapFolding'
75
72
 
76
73
  algorithmSourceModule = algorithmSourceModuleHARDCODED
@@ -84,9 +81,9 @@ def makeDaoOfMapFolding():
84
81
  daoOfMapFolding = IngredientsFunction(inlineFunctionDef(sourceCallableIdentifier, astModule)
85
82
  , LedgerOfImports(astModule))
86
83
 
87
- dataclassName: ast.expr | None = NodeTourist(be.arg, Then.extractIt(DOT.annotation)).captureLastMatch(daoOfMapFolding.astFunctionDef)
84
+ dataclassName: ast.expr | None = NodeTourist(Be.arg, Then.extractIt(DOT.annotation)).captureLastMatch(daoOfMapFolding.astFunctionDef)
88
85
  if dataclassName is None: raise raiseIfNoneGitHubIssueNumber3
89
- dataclass_Identifier: ast_Identifier | None = NodeTourist(be.Name, Then.extractIt(DOT.id)).captureLastMatch(dataclassName)
86
+ dataclass_Identifier: ast_Identifier | None = NodeTourist(Be.Name, Then.extractIt(DOT.id)).captureLastMatch(dataclassName)
90
87
  if dataclass_Identifier is None: raise raiseIfNoneGitHubIssueNumber3
91
88
 
92
89
  dataclassLogicalPathModule = None
@@ -98,7 +95,7 @@ def makeDaoOfMapFolding():
98
95
  if dataclassLogicalPathModule:
99
96
  break
100
97
  if dataclassLogicalPathModule is None: raise raiseIfNoneGitHubIssueNumber3
101
- dataclassInstanceIdentifier = NodeTourist(be.arg, Then.extractIt(DOT.arg)).captureLastMatch(daoOfMapFolding.astFunctionDef)
98
+ dataclassInstanceIdentifier = NodeTourist(Be.arg, Then.extractIt(DOT.arg)).captureLastMatch(daoOfMapFolding.astFunctionDef)
102
99
  if dataclassInstanceIdentifier is None: raise raiseIfNoneGitHubIssueNumber3
103
100
  shatteredDataclass = shatter_dataclassesDOTdataclass(dataclassLogicalPathModule, dataclass_Identifier, dataclassInstanceIdentifier)
104
101
 
@@ -121,13 +118,14 @@ def makeDaoOfMapFolding():
121
118
  doTheNeedful.imports.update(shatteredDataclass.imports)
122
119
  targetCallableIdentifier = daoOfMapFolding.astFunctionDef.name
123
120
  doTheNeedful = unpackDataclassCallFunctionRepackDataclass(doTheNeedful, targetCallableIdentifier, shatteredDataclass)
124
- astTuple: ast.Tuple | None = NodeTourist(be.Return, Then.extractIt(DOT.value)).captureLastMatch(daoOfMapFolding.astFunctionDef)
121
+ astTuple: ast.Tuple | None = NodeTourist(Be.Return, Then.extractIt(DOT.value)).captureLastMatch(daoOfMapFolding.astFunctionDef)
125
122
  if astTuple is None: raise raiseIfNoneGitHubIssueNumber3
126
123
  astTuple.ctx = ast.Store()
127
124
 
128
- findThis = ifThis.isAssignAndValueIs(ifThis.isCall_Identifier(targetCallableIdentifier))
129
- doThat = Then.replaceWith(Make.Assign(listTargets=[astTuple], value=Make.Call(Make.Name(targetCallableIdentifier), astTuple.elts)))
130
- NodeChanger(findThis, doThat).visit(doTheNeedful.astFunctionDef)
125
+ findThis = IfThis.isAssignAndValueIs(IfThis.isCall_Identifier(targetCallableIdentifier))
126
+ doThat = Then.replaceWith(Make.Assign([astTuple], value=Make.Call(Make.Name(targetCallableIdentifier), astTuple.elts)))
127
+ changeAssignCallToTarget = NodeChanger(findThis, doThat)
128
+ changeAssignCallToTarget.visit(doTheNeedful.astFunctionDef)
131
129
 
132
130
  ingredientsModule = IngredientsModule([daoOfMapFolding, doTheNeedful])
133
131
  ingredientsModule.removeImportFromModule('numpy')
@@ -138,7 +136,7 @@ def makeDaoOfMapFolding():
138
136
 
139
137
  return pathFilename
140
138
 
141
- def makeTheorem2():
139
+ def makeTheorem2() -> PurePath:
142
140
  moduleIdentifierHARDCODED: ast_Identifier = 'theorem2'
143
141
 
144
142
  algorithmSourceModule = algorithmSourceModuleHARDCODED
@@ -152,31 +150,31 @@ def makeTheorem2():
152
150
  countTheorem2 = IngredientsFunction(inlineFunctionDef(sourceCallableIdentifier, astModule)
153
151
  , LedgerOfImports(astModule))
154
152
 
155
- dataclassInstanceIdentifier = NodeTourist(be.arg, Then.extractIt(DOT.arg)).captureLastMatch(countTheorem2.astFunctionDef)
153
+ dataclassInstanceIdentifier = NodeTourist(Be.arg, Then.extractIt(DOT.arg)).captureLastMatch(countTheorem2.astFunctionDef)
156
154
  if dataclassInstanceIdentifier is None: raise raiseIfNoneGitHubIssueNumber3
157
155
 
158
- findThis = ifThis.isWhileAttributeNamespace_IdentifierGreaterThan0(dataclassInstanceIdentifier, 'leaf1ndex')
159
- doThat = grab.testAttribute(grab.comparatorsAttribute(Then.replaceWith([Make.Constant(4)]))) # type: ignore
156
+ findThis = IfThis.isWhileAttributeNamespace_IdentifierGreaterThan0(dataclassInstanceIdentifier, 'leaf1ndex')
157
+ doThat = Grab.testAttribute(Grab.comparatorsAttribute(Then.replaceWith([Make.Constant(4)]))) # type: ignore
160
158
  NodeChanger(findThis, doThat).visit(countTheorem2.astFunctionDef)
161
159
 
162
- findThis = ifThis.isIfAttributeNamespace_IdentifierGreaterThan0(dataclassInstanceIdentifier, 'leaf1ndex')
160
+ findThis = IfThis.isIfAttributeNamespace_IdentifierGreaterThan0(dataclassInstanceIdentifier, 'leaf1ndex')
163
161
  doThat = Then.extractIt(DOT.body)
164
162
  insertLeaf = NodeTourist(findThis, doThat).captureLastMatch(countTheorem2.astFunctionDef)
165
- findThis = ifThis.isIfAttributeNamespace_IdentifierGreaterThan0(dataclassInstanceIdentifier, 'leaf1ndex')
163
+ findThis = IfThis.isIfAttributeNamespace_IdentifierGreaterThan0(dataclassInstanceIdentifier, 'leaf1ndex')
166
164
  doThat = Then.replaceWith(insertLeaf)
167
165
  NodeChanger(findThis, doThat).visit(countTheorem2.astFunctionDef)
168
166
 
169
- findThis = ifThis.isAttributeNamespace_IdentifierGreaterThan0(dataclassInstanceIdentifier, 'leaf1ndex')
167
+ findThis = IfThis.isAttributeNamespace_IdentifierGreaterThan0(dataclassInstanceIdentifier, 'leaf1ndex')
170
168
  doThat = Then.removeIt
171
169
  NodeChanger(findThis, doThat).visit(countTheorem2.astFunctionDef)
172
170
 
173
- findThis = ifThis.isAttributeNamespace_IdentifierLessThanOrEqual(dataclassInstanceIdentifier, 'leaf1ndex')
171
+ findThis = IfThis.isAttributeNamespace_IdentifierLessThanOrEqual(dataclassInstanceIdentifier, 'leaf1ndex')
174
172
  doThat = Then.removeIt
175
173
  NodeChanger(findThis, doThat).visit(countTheorem2.astFunctionDef)
176
174
 
177
175
  theCountingIdentifier = theCountingIdentifierHARDCODED
178
176
  doubleTheCount = Make.AugAssign(Make.Attribute(ast.Name(dataclassInstanceIdentifier), theCountingIdentifier), ast.Mult(), Make.Constant(2))
179
- findThis = be.Return
177
+ findThis = Be.Return
180
178
  doThat = Then.insertThisAbove([doubleTheCount])
181
179
  NodeChanger(findThis, doThat).visit(countTheorem2.astFunctionDef)
182
180
 
@@ -188,15 +186,15 @@ def makeTheorem2():
188
186
 
189
187
  return pathFilename
190
188
 
191
- def trimTheorem2(pathFilenameSource: PurePath):
189
+ def trimTheorem2(pathFilenameSource: PurePath) -> PurePath:
192
190
  logicalPathInfix = logicalPathInfixHARDCODED
193
191
  sourceCallableIdentifier = sourceCallableIdentifierHARDCODED
194
192
  ingredientsFunction = astModuleToIngredientsFunction(parsePathFilename2astModule(pathFilenameSource), sourceCallableIdentifier)
195
193
 
196
- dataclassInstanceIdentifier = NodeTourist(be.arg, Then.extractIt(DOT.arg)).captureLastMatch(ingredientsFunction.astFunctionDef)
194
+ dataclassInstanceIdentifier = NodeTourist(Be.arg, Then.extractIt(DOT.arg)).captureLastMatch(ingredientsFunction.astFunctionDef)
197
195
  if dataclassInstanceIdentifier is None: raise raiseIfNoneGitHubIssueNumber3
198
196
 
199
- findThis = ifThis.isIfUnaryNotAttributeNamespace_Identifier(dataclassInstanceIdentifier, 'dimensionsUnconstrained')
197
+ findThis = IfThis.isIfUnaryNotAttributeNamespace_Identifier(dataclassInstanceIdentifier, 'dimensionsUnconstrained')
200
198
  doThat = Then.removeIt
201
199
  NodeChanger(findThis, doThat).visit(ingredientsFunction.astFunctionDef)
202
200
 
@@ -215,17 +213,17 @@ def trimTheorem2(pathFilenameSource: PurePath):
215
213
  logicalPath.append(pathFilename.stem)
216
214
  moduleWithLogicalPath: str_nameDOTname = '.'.join(logicalPath)
217
215
 
218
- astImportFrom: ast.ImportFrom = Make.ImportFrom(moduleWithLogicalPath, list_astAlias=[Make.alias(ingredientsFunction.astFunctionDef.name)])
216
+ astImportFrom: ast.ImportFrom = Make.ImportFrom(moduleWithLogicalPath, list_alias=[Make.alias(ingredientsFunction.astFunctionDef.name)])
219
217
 
220
218
  return pathFilename
221
219
 
222
- def numbaOnTheorem2(pathFilenameSource: PurePath):
220
+ def numbaOnTheorem2(pathFilenameSource: PurePath) -> ast.ImportFrom:
223
221
  logicalPathInfix = logicalPathInfixHARDCODED
224
222
  sourceCallableIdentifier = sourceCallableIdentifierHARDCODED
225
223
  countNumbaTheorem2 = astModuleToIngredientsFunction(parsePathFilename2astModule(pathFilenameSource), sourceCallableIdentifier)
226
- dataclassName: ast.expr | None = NodeTourist(be.arg, Then.extractIt(DOT.annotation)).captureLastMatch(countNumbaTheorem2.astFunctionDef)
224
+ dataclassName: ast.expr | None = NodeTourist(Be.arg, Then.extractIt(DOT.annotation)).captureLastMatch(countNumbaTheorem2.astFunctionDef)
227
225
  if dataclassName is None: raise raiseIfNoneGitHubIssueNumber3
228
- dataclass_Identifier: ast_Identifier | None = NodeTourist(be.Name, Then.extractIt(DOT.id)).captureLastMatch(dataclassName)
226
+ dataclass_Identifier: ast_Identifier | None = NodeTourist(Be.Name, Then.extractIt(DOT.id)).captureLastMatch(dataclassName)
229
227
  if dataclass_Identifier is None: raise raiseIfNoneGitHubIssueNumber3
230
228
 
231
229
  dataclassLogicalPathModule = None
@@ -237,7 +235,7 @@ def numbaOnTheorem2(pathFilenameSource: PurePath):
237
235
  if dataclassLogicalPathModule:
238
236
  break
239
237
  if dataclassLogicalPathModule is None: raise raiseIfNoneGitHubIssueNumber3
240
- dataclassInstanceIdentifier = NodeTourist(be.arg, Then.extractIt(DOT.arg)).captureLastMatch(countNumbaTheorem2.astFunctionDef)
238
+ dataclassInstanceIdentifier = NodeTourist(Be.arg, Then.extractIt(DOT.arg)).captureLastMatch(countNumbaTheorem2.astFunctionDef)
241
239
  if dataclassInstanceIdentifier is None: raise raiseIfNoneGitHubIssueNumber3
242
240
  shatteredDataclass = shatter_dataclassesDOTdataclass(dataclassLogicalPathModule, dataclass_Identifier, dataclassInstanceIdentifier)
243
241
 
@@ -263,11 +261,11 @@ def numbaOnTheorem2(pathFilenameSource: PurePath):
263
261
  logicalPath.append(pathFilename.stem)
264
262
  moduleWithLogicalPath: str_nameDOTname = '.'.join(logicalPath)
265
263
 
266
- astImportFrom: ast.ImportFrom = Make.ImportFrom(moduleWithLogicalPath, list_astAlias=[Make.alias(countNumbaTheorem2.astFunctionDef.name)])
264
+ astImportFrom: ast.ImportFrom = Make.ImportFrom(moduleWithLogicalPath, list_alias=[Make.alias(countNumbaTheorem2.astFunctionDef.name)])
267
265
 
268
266
  return astImportFrom
269
267
 
270
- def makeUnRePackDataclass(astImportFrom: ast.ImportFrom):
268
+ def makeUnRePackDataclass(astImportFrom: ast.ImportFrom) -> None:
271
269
  moduleIdentifierHARDCODED: ast_Identifier = 'dataPacking'
272
270
 
273
271
  algorithmSourceModule = algorithmSourceModuleHARDCODED
@@ -278,9 +276,9 @@ def makeUnRePackDataclass(astImportFrom: ast.ImportFrom):
278
276
  moduleIdentifier = moduleIdentifierHARDCODED
279
277
 
280
278
  doTheNeedful: IngredientsFunction = astModuleToIngredientsFunction(parseLogicalPath2astModule(logicalPathSourceModule), sourceCallableIdentifier)
281
- dataclassName: ast.expr | None = NodeTourist(be.arg, Then.extractIt(DOT.annotation)).captureLastMatch(doTheNeedful.astFunctionDef)
279
+ dataclassName: ast.expr | None = NodeTourist(Be.arg, Then.extractIt(DOT.annotation)).captureLastMatch(doTheNeedful.astFunctionDef)
282
280
  if dataclassName is None: raise raiseIfNoneGitHubIssueNumber3
283
- dataclass_Identifier: ast_Identifier | None = NodeTourist(be.Name, Then.extractIt(DOT.id)).captureLastMatch(dataclassName)
281
+ dataclass_Identifier: ast_Identifier | None = NodeTourist(Be.Name, Then.extractIt(DOT.id)).captureLastMatch(dataclassName)
284
282
  if dataclass_Identifier is None: raise raiseIfNoneGitHubIssueNumber3
285
283
 
286
284
  dataclassLogicalPathModule = None
@@ -292,7 +290,7 @@ def makeUnRePackDataclass(astImportFrom: ast.ImportFrom):
292
290
  if dataclassLogicalPathModule:
293
291
  break
294
292
  if dataclassLogicalPathModule is None: raise raiseIfNoneGitHubIssueNumber3
295
- dataclassInstanceIdentifier = NodeTourist(be.arg, Then.extractIt(DOT.arg)).captureLastMatch(doTheNeedful.astFunctionDef)
293
+ dataclassInstanceIdentifier = NodeTourist(Be.arg, Then.extractIt(DOT.arg)).captureLastMatch(doTheNeedful.astFunctionDef)
296
294
  if dataclassInstanceIdentifier is None: raise raiseIfNoneGitHubIssueNumber3
297
295
  shatteredDataclass = shatter_dataclassesDOTdataclass(dataclassLogicalPathModule, dataclass_Identifier, dataclassInstanceIdentifier)
298
296
 
@@ -300,14 +298,15 @@ def makeUnRePackDataclass(astImportFrom: ast.ImportFrom):
300
298
  doTheNeedful.imports.addAst(astImportFrom)
301
299
  targetCallableIdentifier = astImportFrom.names[0].name
302
300
  doTheNeedful = unpackDataclassCallFunctionRepackDataclass(doTheNeedful, targetCallableIdentifier, shatteredDataclass)
303
- targetFunctionDef = extractFunctionDef(parseLogicalPath2astModule(astImportFrom.module), targetCallableIdentifier) # type: ignore
301
+ if astImportFrom.module is None: raise raiseIfNoneGitHubIssueNumber3
302
+ targetFunctionDef = extractFunctionDef(parseLogicalPath2astModule(astImportFrom.module), targetCallableIdentifier)
304
303
  if targetFunctionDef is None: raise raiseIfNoneGitHubIssueNumber3
305
- astTuple: ast.Tuple | None = NodeTourist(be.Return, Then.extractIt(DOT.value)).captureLastMatch(targetFunctionDef)
304
+ astTuple: ast.Tuple | None = NodeTourist(Be.Return, Then.extractIt(DOT.value)).captureLastMatch(targetFunctionDef)
306
305
  if astTuple is None: raise raiseIfNoneGitHubIssueNumber3
307
306
  astTuple.ctx = ast.Store()
308
307
 
309
- findThis = ifThis.isAssignAndValueIs(ifThis.isCall_Identifier(targetCallableIdentifier))
310
- doThat = Then.replaceWith(Make.Assign(listTargets=[astTuple], value=Make.Call(Make.Name(targetCallableIdentifier), astTuple.elts)))
308
+ findThis = IfThis.isAssignAndValueIs(IfThis.isCall_Identifier(targetCallableIdentifier))
309
+ doThat = Then.replaceWith(Make.Assign([astTuple], value=Make.Call(Make.Name(targetCallableIdentifier), astTuple.elts)))
311
310
  NodeChanger(findThis, doThat).visit(doTheNeedful.astFunctionDef)
312
311
 
313
312
  ingredientsModule = IngredientsModule(doTheNeedful)
@@ -44,54 +44,36 @@ optimizations - while maintaining the ability to verify correctness at each tran
44
44
  test suite.
45
45
  """
46
46
 
47
- from mapFolding.someAssemblyRequired._theTypes import (
47
+ from astToolkit import (
48
48
  ast_expr_Slice as ast_expr_Slice,
49
49
  ast_Identifier as ast_Identifier,
50
- astClassHasDOTbody as astClassHasDOTbody,
51
- astClassHasDOTbody_expr as astClassHasDOTbody_expr,
52
- astClassHasDOTbodyList_stmt as astClassHasDOTbodyList_stmt,
53
- astClassHasDOTnameNotName as astClassHasDOTnameNotName,
54
- astClassHasDOTnameNotNameAlways as astClassHasDOTnameNotNameAlways,
55
- astClassHasDOTnameNotNameOptionally as astClassHasDOTnameNotNameOptionally,
56
- astClassHasDOTtarget as astClassHasDOTtarget,
57
- astClassHasDOTtarget_expr as astClassHasDOTtarget_expr,
58
- astClassHasDOTtargetAttributeNameSubscript as astClassHasDOTtargetAttributeNameSubscript,
59
- astClassHasDOTvalue as astClassHasDOTvalue,
60
- astClassHasDOTvalue_expr as astClassHasDOTvalue_expr,
61
- astClassHasDOTvalue_exprNone as astClassHasDOTvalue_exprNone,
50
+ astModuleToIngredientsFunction as astModuleToIngredientsFunction,
51
+ Be as Be,
52
+ DOT as DOT,
53
+ extractClassDef as extractClassDef,
54
+ extractFunctionDef as extractFunctionDef,
55
+ Grab as Grab,
62
56
  ImaCallToName as ImaCallToName,
63
- intORlist_ast_type_paramORstr_orNone as intORlist_ast_type_paramORstr_orNone,
64
- intORstr_orNone as intORstr_orNone,
65
- list_ast_type_paramORstr_orNone as list_ast_type_paramORstr_orNone,
66
- NodeORattribute as NodeORattribute,
67
- str_nameDOTname as str_nameDOTname,
68
- 个 as 个,
69
- )
70
-
71
- from mapFolding.someAssemblyRequired._toolboxPython import (
72
57
  importLogicalPath2Callable as importLogicalPath2Callable,
73
58
  importPathFilename2Callable as importPathFilename2Callable,
59
+ IngredientsFunction as IngredientsFunction,
60
+ IngredientsModule as IngredientsModule,
61
+ LedgerOfImports as LedgerOfImports,
62
+ Make as Make,
74
63
  NodeChanger as NodeChanger,
64
+ NodeORattribute as NodeORattribute,
75
65
  NodeTourist as NodeTourist,
76
66
  parseLogicalPath2astModule as parseLogicalPath2astModule,
77
67
  parsePathFilename2astModule as parsePathFilename2astModule,
78
- )
68
+ str_nameDOTname as str_nameDOTname,
69
+ Then as Then,
70
+ 个 as 个,
71
+ )
79
72
 
80
- from mapFolding.someAssemblyRequired._toolboxAntecedents import be as be, DOT as DOT, ifThis as ifThis
81
- from mapFolding.someAssemblyRequired._tool_Make import Make as Make
82
- from mapFolding.someAssemblyRequired._tool_Then import grab as grab, Then as Then
73
+ from mapFolding.someAssemblyRequired._toolIfThis import IfThis as IfThis
83
74
 
84
75
  from mapFolding.someAssemblyRequired._toolboxContainers import (
85
76
  DeReConstructField2ast as DeReConstructField2ast,
86
- IngredientsFunction as IngredientsFunction,
87
- IngredientsModule as IngredientsModule,
88
- LedgerOfImports as LedgerOfImports,
89
77
  RecipeSynthesizeFlow as RecipeSynthesizeFlow,
90
78
  ShatteredDataclass as ShatteredDataclass,
91
79
  )
92
-
93
- from mapFolding.someAssemblyRequired._toolboxAST import (
94
- astModuleToIngredientsFunction as astModuleToIngredientsFunction,
95
- extractClassDef as extractClassDef,
96
- extractFunctionDef as extractFunctionDef,
97
- )
@@ -0,0 +1,53 @@
1
+ """
2
+ AST Node Predicate and Access Utilities for Pattern Matching and Traversal
3
+
4
+ This module provides utilities for accessing and matching AST nodes in a consistent way. It contains three primary
5
+ classes:
6
+
7
+ 1. DOT: Provides consistent accessor methods for AST node attributes across different node types, simplifying the access
8
+ to node properties.
9
+
10
+ 2. be: Offers type-guard functions that verify AST node types, enabling safe type narrowing for static type checking and
11
+ improving code safety.
12
+
13
+ 3. ifThis: Contains predicate functions for matching AST nodes based on various criteria, enabling precise targeting of
14
+ nodes for analysis or transformation.
15
+
16
+ These utilities form the foundation of the pattern-matching component in the AST manipulation framework, working in
17
+ conjunction with the NodeChanger and NodeTourist classes to enable precise and targeted code transformations. Together,
18
+ they implement a declarative approach to AST manipulation that separates node identification (ifThis), type verification
19
+ (be), and data access (DOT).
20
+ """
21
+
22
+ from astToolkit import IfThis as astToolkit_IfThis
23
+ from collections.abc import Callable
24
+ from mapFolding.someAssemblyRequired import ast_Identifier, Be
25
+ from typing import TypeGuard
26
+ import ast
27
+
28
+ class IfThis(astToolkit_IfThis):
29
+ """
30
+ Provide predicate functions for matching and filtering AST nodes based on various criteria.
31
+
32
+ The ifThis class contains static methods that generate predicate functions used to test whether AST nodes match
33
+ specific criteria. These predicates can be used with NodeChanger and NodeTourist to identify and process specific
34
+ patterns in the AST.
35
+
36
+ The class provides predicates for matching various node types, attributes, identifiers, and structural patterns,
37
+ enabling precise targeting of AST elements for analysis or transformation.
38
+ """
39
+ @staticmethod
40
+ def isAttributeNamespace_IdentifierGreaterThan0(namespace: ast_Identifier, identifier: ast_Identifier) -> Callable[[ast.AST], TypeGuard[ast.Compare] | bool]:
41
+ return lambda node: (Be.Compare(node)
42
+ and IfThis.isAttributeNamespace_Identifier(namespace, identifier)(node.left)
43
+ and Be.Gt(node.ops[0])
44
+ and IfThis.isConstant_value(0)(node.comparators[0]))
45
+ @staticmethod
46
+ def isIfAttributeNamespace_IdentifierGreaterThan0(namespace: ast_Identifier, identifier: ast_Identifier) -> Callable[[ast.AST], TypeGuard[ast.If] | bool]:
47
+ return lambda node: (Be.If(node)
48
+ and IfThis.isAttributeNamespace_IdentifierGreaterThan0(namespace, identifier)(node.test))
49
+
50
+ @staticmethod
51
+ def isWhileAttributeNamespace_IdentifierGreaterThan0(namespace: ast_Identifier, identifier: ast_Identifier) -> Callable[[ast.AST], TypeGuard[ast.While] | bool]:
52
+ return lambda node: (Be.While(node)
53
+ and IfThis.isAttributeNamespace_IdentifierGreaterThan0(namespace, identifier)(node.test))