mapFolding 0.9.5__py3-none-any.whl → 0.10.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.
Files changed (28) hide show
  1. mapFolding/someAssemblyRequired/Z0Z_makeSomeModules.py +43 -42
  2. mapFolding/someAssemblyRequired/__init__.py +12 -21
  3. mapFolding/someAssemblyRequired/_astTypes.py +117 -0
  4. mapFolding/someAssemblyRequired/_theTypes.py +4 -27
  5. mapFolding/someAssemblyRequired/_toolBe.py +524 -0
  6. mapFolding/someAssemblyRequired/_toolDOT.py +493 -0
  7. mapFolding/someAssemblyRequired/_toolGrab.py +653 -0
  8. mapFolding/someAssemblyRequired/_toolIfThis.py +193 -0
  9. mapFolding/someAssemblyRequired/_toolMake.py +339 -0
  10. mapFolding/someAssemblyRequired/_toolThen.py +63 -0
  11. mapFolding/someAssemblyRequired/_toolboxAST.py +3 -3
  12. mapFolding/someAssemblyRequired/_toolboxContainers.py +4 -4
  13. mapFolding/someAssemblyRequired/makeJobTheorem2Numba.py +9 -9
  14. mapFolding/someAssemblyRequired/synthesizeNumbaJob.py +9 -9
  15. mapFolding/someAssemblyRequired/toolboxNumba.py +1 -1
  16. mapFolding/someAssemblyRequired/transformationTools.py +39 -36
  17. mapFolding/toolFactory/astFactory.py +493 -0
  18. mapFolding/toolFactory/astFactory_annex.py +63 -0
  19. mapFolding/toolFactory/astFactory_docstrings.py +63 -0
  20. {mapfolding-0.9.5.dist-info → mapfolding-0.10.0.dist-info}/METADATA +2 -1
  21. {mapfolding-0.9.5.dist-info → mapfolding-0.10.0.dist-info}/RECORD +25 -18
  22. {mapfolding-0.9.5.dist-info → mapfolding-0.10.0.dist-info}/WHEEL +1 -1
  23. mapFolding/someAssemblyRequired/_tool_Make.py +0 -132
  24. mapFolding/someAssemblyRequired/_tool_Then.py +0 -152
  25. mapFolding/someAssemblyRequired/_toolboxAntecedents.py +0 -404
  26. {mapfolding-0.9.5.dist-info → mapfolding-0.10.0.dist-info}/entry_points.txt +0 -0
  27. {mapfolding-0.9.5.dist-info → mapfolding-0.10.0.dist-info}/licenses/LICENSE +0 -0
  28. {mapfolding-0.9.5.dist-info → mapfolding-0.10.0.dist-info}/top_level.txt +0 -0
@@ -22,20 +22,24 @@ mapFolding/reference/jobsCompleted/__init__.py,sha256=TU93ZGUW1xEkT6d9mQFn_rp5Dv
22
22
  mapFolding/reference/jobsCompleted/[2x19]/p2x19.py,sha256=_tvYtfzMWVo2VtUbIAieoscb4N8FFflgTdW4-ljBUuA,19626
23
23
  mapFolding/reference/jobsCompleted/p2x19/p2x19.py,sha256=eZEw4Me4ocTt6VXoK2-Sbd5SowZtxRIbN9dZmc7OCVg,6395
24
24
  mapFolding/someAssemblyRequired/RecipeJob.py,sha256=6RD4F4Yde7K-Rz0F4IokQ62BVzRSx4vCCYY4H-Dfug4,10190
25
- mapFolding/someAssemblyRequired/Z0Z_makeSomeModules.py,sha256=ctR-0wwGpDSHfa7pF4dhJwbWzptADWb4m6AQeN9KabA,15677
26
- mapFolding/someAssemblyRequired/__init__.py,sha256=fIdXu8UVLp2ccGdaQO41qmlfa87tWRgevGJH2xSdUkY,4570
27
- mapFolding/someAssemblyRequired/_theTypes.py,sha256=CUw-8_6tyOU6q3r_Fe5PQsvRdw04LQ2bDuTg1X1XRtk,5002
28
- mapFolding/someAssemblyRequired/_tool_Make.py,sha256=Ou2EGtMe1SCv_v_s0tEMVz_VlXgGhyk9nZxipQ5Ez_0,7651
29
- mapFolding/someAssemblyRequired/_tool_Then.py,sha256=8gdAQ7NPHzS6Q_NERbjzA3JtyO2N62jOmiDOx9Tq1l8,6168
30
- mapFolding/someAssemblyRequired/_toolboxAST.py,sha256=Wm0XUqqxKbwu1kIQ1F6iXEP2z25qmr1JsZ2CeWMBtLg,2376
31
- mapFolding/someAssemblyRequired/_toolboxAntecedents.py,sha256=i1jOdK1nJlA0blbVlCWJf-CeHyPgUf7QMQSFm1BrhQ8,16682
32
- mapFolding/someAssemblyRequired/_toolboxContainers.py,sha256=Qtf1vGPIYQ9g2bOiupkm_-T4Qsr7p14SSI9eXcmT54M,30125
25
+ mapFolding/someAssemblyRequired/Z0Z_makeSomeModules.py,sha256=ni7twaO2Pkrhg-BXuxysF-reNLb79_jcpQp6AcHJ98E,15770
26
+ mapFolding/someAssemblyRequired/__init__.py,sha256=4PIwIa8iAX3h3O2_bdWjsfiFtHwnXCY85x6EdJrmh0g,3882
27
+ mapFolding/someAssemblyRequired/_astTypes.py,sha256=EwLxEtbZwUtaRlt4tWwiTvaoeGR4_V3hdX8Xi3Z8w1E,7809
28
+ mapFolding/someAssemblyRequired/_theTypes.py,sha256=8Ako7EVwciwdNoXLTpAQaOgMTgQv2HysXzPPYMwBv68,3107
29
+ mapFolding/someAssemblyRequired/_toolBe.py,sha256=bT64xwj_lGJZZB6FyY46alFZENZ2LlJdb2kO47L643Q,16400
30
+ mapFolding/someAssemblyRequired/_toolDOT.py,sha256=JpEpW0mZRFFYzlIhQQtD15rKSzEESXfzX6i0aH95YK0,12727
31
+ mapFolding/someAssemblyRequired/_toolGrab.py,sha256=oMrTMVky5BIEo9GEXA3AVlElGtPd10gIR6jIEWWsFV8,25327
32
+ mapFolding/someAssemblyRequired/_toolIfThis.py,sha256=DsvXHvi27YGC8TZMm6WlV6YsK0ruVPVPQRip0wrpvlk,10223
33
+ mapFolding/someAssemblyRequired/_toolMake.py,sha256=X54TBZysYEcVOmtBSTZoW80kmJJS-yYFwRvN_19uU_8,18282
34
+ mapFolding/someAssemblyRequired/_toolThen.py,sha256=RFp1h8FQroBIR3F-TtXJo3j7wS_XKFAvLWly93PkZiE,2584
35
+ mapFolding/someAssemblyRequired/_toolboxAST.py,sha256=-hlKH0gYCY4Srx1azL8SK2RLbYYRw0a0i3qaYcnx8L0,2376
36
+ mapFolding/someAssemblyRequired/_toolboxContainers.py,sha256=5Y9-X-SyCkrxpn164PICvcimPE89Tgcnksm7N5wqOnU,30117
33
37
  mapFolding/someAssemblyRequired/_toolboxPython.py,sha256=1K7IzqzmHNTaPA6qTo73GZYHCIQRYI2Rn8aYJ3VelqY,7873
34
38
  mapFolding/someAssemblyRequired/getLLVMforNoReason.py,sha256=9RPU6vK_eUg64GtVFI_nZnvUryXw8gfHJs9NyDYHIvg,2745
35
- mapFolding/someAssemblyRequired/makeJobTheorem2Numba.py,sha256=rVsBWkRr9biR_kMRwkn8z4gGHu3hKwigZ-WoSC1nkEA,13830
36
- mapFolding/someAssemblyRequired/synthesizeNumbaJob.py,sha256=bhCCEBEPco2gwaaieH3SADZnFyQBrvBYOzZs9-cyXAs,15597
37
- mapFolding/someAssemblyRequired/toolboxNumba.py,sha256=MkVmX844CDnEpodY5sasAYjK4gBbO9icoRhvX241Ipc,8965
38
- mapFolding/someAssemblyRequired/transformationTools.py,sha256=UikTtBxW2LfGpMiOirDUB928V-OcHPTXsO1KTxAL1O0,29326
39
+ mapFolding/someAssemblyRequired/makeJobTheorem2Numba.py,sha256=5j3fLdiVHv7OlH-RR-fjeevRXnLrmUJpeXleHytDoF4,13830
40
+ mapFolding/someAssemblyRequired/synthesizeNumbaJob.py,sha256=9D0VLOAttfyTcf8GFko_QhRS5steSQo6FvWHD5xQLGc,15597
41
+ mapFolding/someAssemblyRequired/toolboxNumba.py,sha256=QIpYCf1IFfgrQ5GVA0ON0ymn324iBfkyHVSfBW5CqOY,8961
42
+ mapFolding/someAssemblyRequired/transformationTools.py,sha256=Kd_eVIgBHMdsZwOIe9hxST0x1JfqgCR26OyNBYjDSY0,29307
39
43
  mapFolding/syntheticModules/__init__.py,sha256=evVFqhCGa-WZKDiLcnQWjs-Bj34eRnfSLqz_d7dFYZY,83
40
44
  mapFolding/syntheticModules/daoOfMapFolding.py,sha256=cfWPABtXyCxJ0BwPI7rhfLh_2UYV_XKAL8lJ4GLNXaQ,5896
41
45
  mapFolding/syntheticModules/dataPacking.py,sha256=J4WLJzQTOAm2d8itzWWSixTUcCGQl4KuEfqrzkb2tJQ,2294
@@ -44,7 +48,10 @@ mapFolding/syntheticModules/numbaCount.py,sha256=zM-bp07c9tEDdvidwzZ_bJTd0JC0VUk
44
48
  mapFolding/syntheticModules/theorem2.py,sha256=9jrbZNNX4BWYZW1S0JjvRY2k7RU7I1RNUMV7JdCt1ZY,3017
45
49
  mapFolding/syntheticModules/theorem2Numba.py,sha256=-cKjNyxgUMFhEyFVs0VJ7hw4LfrV0WSNK5tPYbQ1oNU,3369
46
50
  mapFolding/syntheticModules/theorem2Trimmed.py,sha256=DHW3NxBdtABQYBKm2WRvfQ5kzc2_UwGI2h4ePuYEJoM,2685
47
- mapfolding-0.9.5.dist-info/licenses/LICENSE,sha256=NxH5Y8BdC-gNU-WSMwim3uMbID2iNDXJz7fHtuTdXhk,19346
51
+ mapFolding/toolFactory/astFactory.py,sha256=3FJUx_O7L7rM9gyeUvYGB1rRm0gmqiTos4_CjboQ4KI,28777
52
+ mapFolding/toolFactory/astFactory_annex.py,sha256=pTULZ8bJ4ioojK2VQ2636rvlHflT0GbSeHYjm2kooqE,5948
53
+ mapFolding/toolFactory/astFactory_docstrings.py,sha256=aX2JR5cXMe2znIrvWxLeK74jQebMWwGX4U0sk-iexWQ,3406
54
+ mapfolding-0.10.0.dist-info/licenses/LICENSE,sha256=NxH5Y8BdC-gNU-WSMwim3uMbID2iNDXJz7fHtuTdXhk,19346
48
55
  tests/__init__.py,sha256=5VhHf0JJ2_DSh58zJ0rR5UkpoCon-0IkdljspTCzZ04,1950
49
56
  tests/conftest.py,sha256=x8zMZQyTss3sn0GwHm_TSRwD9_LVlR8l_qF8r43Vxl4,14178
50
57
  tests/test_computations.py,sha256=5sg1PpSp6aeOrXZeO5NwWK5ipPAe49wVKC2J7yT5MFg,6524
@@ -52,8 +59,8 @@ tests/test_filesystem.py,sha256=T2DkjBoI3lW6tCxd5BilPmUFrVukNKLjOOZVZxLM560,3004
52
59
  tests/test_oeis.py,sha256=uxvwmgbnylSDdsVJfuAT0LuYLbIVFwSgdLxHm-xUGBM,5043
53
60
  tests/test_other.py,sha256=UMlK4JPInalpOZuPvTnUrgXWCJOxAw-OsPs6CxMR254,3753
54
61
  tests/test_tasks.py,sha256=tOQc4uomKXGwWnENfbcThaVa1XofwXNCkGZbg4yS6VI,2833
55
- mapfolding-0.9.5.dist-info/METADATA,sha256=Wxvk-PufaaR_0jvSlJjgBYKoEzZi15KtZipJdP7XOAE,7502
56
- mapfolding-0.9.5.dist-info/WHEEL,sha256=pxyMxgL8-pra_rKaQ4drOZAegBVuX-G_4nRHjjgWbmo,91
57
- mapfolding-0.9.5.dist-info/entry_points.txt,sha256=F3OUeZR1XDTpoH7k3wXuRb3KF_kXTTeYhu5AGK1SiOQ,146
58
- mapfolding-0.9.5.dist-info/top_level.txt,sha256=1gP2vFaqPwHujGwb3UjtMlLEGN-943VSYFR7V4gDqW8,17
59
- mapfolding-0.9.5.dist-info/RECORD,,
62
+ mapfolding-0.10.0.dist-info/METADATA,sha256=jcIwCSmk1EYzJDUvvQ3BE5-VYswynF9onfnMS7Humlg,7534
63
+ mapfolding-0.10.0.dist-info/WHEEL,sha256=SmOxYU7pzNKBqASvQJ7DjX3XGUF92lrGhMb3R6_iiqI,91
64
+ mapfolding-0.10.0.dist-info/entry_points.txt,sha256=F3OUeZR1XDTpoH7k3wXuRb3KF_kXTTeYhu5AGK1SiOQ,146
65
+ mapfolding-0.10.0.dist-info/top_level.txt,sha256=1gP2vFaqPwHujGwb3UjtMlLEGN-943VSYFR7V4gDqW8,17
66
+ mapfolding-0.10.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (79.0.0)
2
+ Generator: setuptools (79.0.1)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,132 +0,0 @@
1
- """
2
- AST Node Construction Utilities for Python Code Generation
3
-
4
- This module provides the Make class with static methods for creating AST nodes with sane defaults. It abstracts away the
5
- complexity of constructing AST nodes directly, making programmatic code generation more intuitive and less error-prone.
6
-
7
- The Make class serves as a factory for creating various types of AST nodes needed in code generation, transformation,
8
- and analysis workflows. Each method follows a consistent pattern that maps cleanly to Python's syntax while handling the
9
- details of AST node construction.
10
- """
11
-
12
- from collections.abc import Sequence
13
- from mapFolding.someAssemblyRequired import (
14
- ast_expr_Slice,
15
- ast_Identifier,
16
- intORlist_ast_type_paramORstr_orNone,
17
- intORstr_orNone,
18
- list_ast_type_paramORstr_orNone,
19
- str_nameDOTname,
20
- )
21
- from typing import Any
22
- import ast
23
-
24
- class Make:
25
- """Almost all parameters described here are only accessible through a method's `**keywordArguments` parameter.
26
-
27
- Parameters:
28
- context (ast.Load()): Are you loading from, storing to, or deleting the identifier? The `context` (also, `ctx`) value is `ast.Load()`, `ast.Store()`, or `ast.Del()`.
29
- col_offset (0): int Position information specifying the column where an AST node begins.
30
- end_col_offset (None): int|None Position information specifying the column where an AST node ends.
31
- end_lineno (None): int|None Position information specifying the line number where an AST node ends.
32
- level (0): int Module import depth level that controls relative vs absolute imports. Default 0 indicates absolute import.
33
- lineno: int Position information manually specifying the line number where an AST node begins.
34
- kind (None): str|None Used for type annotations in limited cases.
35
- type_comment (None): str|None "type_comment is an optional string with the type annotation as a comment." or `# type: ignore`.
36
- type_params: list[ast.type_param] Type parameters for generic type definitions.
37
-
38
- The `ast._Attributes`, lineno, col_offset, end_lineno, and end_col_offset, hold position information; however, they are, importantly, _not_ `ast._fields`.
39
- """
40
- @staticmethod
41
- def alias(name: ast_Identifier, asname: ast_Identifier | None = None) -> ast.alias:
42
- return ast.alias(name, asname)
43
-
44
- @staticmethod
45
- def AnnAssign(target: ast.Attribute | ast.Name | ast.Subscript, annotation: ast.expr, value: ast.expr | None = None, **keywordArguments: int) -> ast.AnnAssign: # `simple: int`: uses a clever int-from-boolean to assign the correct value to the `simple` attribute. So, don't make it a method parameter.
46
- return ast.AnnAssign(target, annotation, value, simple=int(isinstance(target, ast.Name)), **keywordArguments)
47
-
48
- @staticmethod
49
- def arg(identifier: ast_Identifier, annotation: ast.expr | None = None, **keywordArguments: intORstr_orNone) -> ast.arg:
50
- return ast.arg(identifier, annotation, **keywordArguments)
51
-
52
- @staticmethod
53
- def argumentsSpecification(posonlyargs:list[ast.arg]=[], args:list[ast.arg]=[], vararg:ast.arg|None=None, kwonlyargs:list[ast.arg]=[], kw_defaults:list[ast.expr|None]=[None], kwarg:ast.arg|None=None, defaults:list[ast.expr]=[]) -> ast.arguments:
54
- return ast.arguments(posonlyargs, args, vararg, kwonlyargs, kw_defaults, kwarg, defaults)
55
-
56
- @staticmethod
57
- def Assign(listTargets: list[ast.expr], value: ast.expr, **keywordArguments: intORstr_orNone) -> ast.Assign:
58
- return ast.Assign(listTargets, value, **keywordArguments)
59
-
60
- @staticmethod
61
- def Attribute(value: ast.expr, *attribute: ast_Identifier, context: ast.expr_context = ast.Load(), **keywordArguments: int) -> ast.Attribute:
62
- """ If two `ast_Identifier` are joined by a dot `.`, they are _usually_ an `ast.Attribute`, but see `ast.ImportFrom`.
63
- Parameters:
64
- value: the part before the dot (e.g., `ast.Name`.)
65
- attribute: an `ast_Identifier` after a dot `.`; you can pass multiple `attribute` and they will be chained together.
66
- """
67
- def addDOTattribute(chain: ast.expr, identifier: ast_Identifier, context: ast.expr_context, **keywordArguments: int) -> ast.Attribute:
68
- return ast.Attribute(value=chain, attr=identifier, ctx=context, **keywordArguments)
69
- buffaloBuffalo = addDOTattribute(value, attribute[0], context, **keywordArguments)
70
- for identifier in attribute[1:None]:
71
- buffaloBuffalo = addDOTattribute(buffaloBuffalo, identifier, context, **keywordArguments)
72
- return buffaloBuffalo
73
-
74
- @staticmethod
75
- def AugAssign(target: ast.Attribute | ast.Name | ast.Subscript, operator: ast.operator, value: ast.expr, **keywordArguments: int) -> ast.AugAssign:
76
- return ast.AugAssign(target, operator, value, **keywordArguments)
77
-
78
- @staticmethod
79
- def Call(callee: ast.expr, listArguments: Sequence[ast.expr] | None = None, list_astKeywords: Sequence[ast.keyword] | None = None) -> ast.Call:
80
- return ast.Call(func=callee, args=list(listArguments) if listArguments else [], keywords=list(list_astKeywords) if list_astKeywords else [])
81
-
82
- @staticmethod
83
- def ClassDef(name: ast_Identifier, listBases: list[ast.expr]=[], list_keyword: list[ast.keyword]=[], body: list[ast.stmt]=[], decorator_list: list[ast.expr]=[], **keywordArguments: list_ast_type_paramORstr_orNone) -> ast.ClassDef:
84
- return ast.ClassDef(name, listBases, list_keyword, body, decorator_list, **keywordArguments)
85
-
86
- @staticmethod
87
- def Constant(value: Any, **keywordArguments: intORstr_orNone) -> ast.Constant:
88
- return ast.Constant(value, **keywordArguments)
89
-
90
- @staticmethod
91
- def Expr(value: ast.expr, **keywordArguments: int) -> ast.Expr:
92
- return ast.Expr(value, **keywordArguments)
93
-
94
- @staticmethod
95
- def FunctionDef(name: ast_Identifier, argumentsSpecification:ast.arguments=ast.arguments(), body:list[ast.stmt]=[], decorator_list:list[ast.expr]=[], returns:ast.expr|None=None, **keywordArguments: intORlist_ast_type_paramORstr_orNone) -> ast.FunctionDef:
96
- return ast.FunctionDef(name, argumentsSpecification, body, decorator_list, returns, **keywordArguments)
97
-
98
- @staticmethod
99
- def Import(moduleWithLogicalPath: str_nameDOTname, asname: ast_Identifier | None = None, **keywordArguments: int) -> ast.Import:
100
- return ast.Import(names=[Make.alias(moduleWithLogicalPath, asname)], **keywordArguments)
101
-
102
- @staticmethod
103
- def ImportFrom(moduleWithLogicalPath: str_nameDOTname, list_astAlias: list[ast.alias], **keywordArguments: int) -> ast.ImportFrom:
104
- return ast.ImportFrom(moduleWithLogicalPath, list_astAlias, **keywordArguments)
105
-
106
- @staticmethod
107
- def keyword(keywordArgument: ast_Identifier, value: ast.expr, **keywordArguments: int) -> ast.keyword:
108
- return ast.keyword(arg=keywordArgument, value=value, **keywordArguments)
109
-
110
- @staticmethod
111
- def Module(body: list[ast.stmt] = [], type_ignores: list[ast.TypeIgnore] = []) -> ast.Module:
112
- return ast.Module(body, type_ignores)
113
-
114
- @staticmethod
115
- def Name(identifier: ast_Identifier, context: ast.expr_context = ast.Load(), **keywordArguments: int) -> ast.Name:
116
- return ast.Name(identifier, context, **keywordArguments)
117
-
118
- @staticmethod
119
- def Return(value: ast.expr | None = None, **keywordArguments: int) -> ast.Return:
120
- return ast.Return(value, **keywordArguments)
121
-
122
- @staticmethod
123
- def Subscript(value: ast.expr, slice: ast_expr_Slice, context: ast.expr_context = ast.Load(), **keywordArguments: int) -> ast.Subscript:
124
- return ast.Subscript(value, slice, context, **keywordArguments)
125
-
126
- @staticmethod
127
- def Tuple(elements: Sequence[ast.expr] = [], context: ast.expr_context = ast.Load(), **keywordArguments: int) -> ast.Tuple:
128
- return ast.Tuple(list(elements), context, **keywordArguments)
129
-
130
- @staticmethod
131
- def While(test: ast.expr, doThis: list[ast.stmt], orElse: list[ast.stmt] = [], **keywordArguments: int) -> ast.While:
132
- return ast.While(test, doThis, orElse, **keywordArguments)
@@ -1,152 +0,0 @@
1
- """
2
- AST Node Transformation Actions for Python Code Manipulation
3
-
4
- This module provides the Then class with static methods for generating callable action functions that specify what to do
5
- with AST nodes that match predicates. These action functions are used primarily with NodeChanger and NodeTourist to
6
- transform or extract information from AST nodes.
7
-
8
- The module also contains the grab class that provides functions for modifying specific attributes of AST nodes while
9
- preserving their structure, enabling fine-grained control when transforming AST structures.
10
-
11
- Together, these classes provide a complete system for manipulating AST nodes once they have been identified using
12
- predicate functions from ifThis.
13
- """
14
-
15
- from collections.abc import Callable, Sequence
16
- from mapFolding.someAssemblyRequired import ast_Identifier, astClassHasDOTvalue, ImaCallToName, NodeORattribute
17
- from typing import Any
18
- import ast
19
-
20
- class grab:
21
- """
22
- Modify specific attributes of AST nodes while preserving the node structure.
23
-
24
- The grab class provides static methods that create transformation functions to modify specific attributes of AST
25
- nodes. Unlike DOT which provides read-only access, grab allows for targeted modifications of node attributes without
26
- replacing the entire node.
27
-
28
- Each method returns a function that takes a node, applies a transformation to a specific attribute of that node, and
29
- returns the modified node. This enables fine-grained control when transforming AST structures.
30
- """
31
- @staticmethod
32
- def andDoAllOf(listOfActions: list[Callable[[NodeORattribute], NodeORattribute]]) -> Callable[[NodeORattribute], NodeORattribute]:
33
- def workhorse(node: NodeORattribute) -> NodeORattribute:
34
- for action in listOfActions:
35
- node = action(node)
36
- return node
37
- return workhorse
38
-
39
- @staticmethod
40
- def argAttribute(action: Callable[[ast_Identifier | None], ast_Identifier]) -> Callable[[ast.arg | ast.keyword], ast.arg | ast.keyword]:
41
- def workhorse(node: ast.arg | ast.keyword) -> ast.arg | ast.keyword:
42
- node.arg = action(node.arg)
43
- return node
44
- return workhorse
45
-
46
- @staticmethod
47
- def attrAttribute(action: Callable[[ast_Identifier], ast_Identifier]) -> Callable[[ast.Attribute], ast.Attribute]:
48
- def workhorse(node: ast.Attribute) -> ast.Attribute:
49
- node.attr = action(node.attr)
50
- return node
51
- return workhorse
52
-
53
- @staticmethod
54
- def comparatorsAttribute(action: Callable[[list[ast.expr]], list[ast.expr]]) -> Callable[[ast.Compare], ast.Compare]:
55
- def workhorse(node: ast.Compare) -> ast.Compare:
56
- node.comparators = action(node.comparators)
57
- return node
58
- return workhorse
59
-
60
- @staticmethod
61
- def funcAttribute(action: Callable[[ast.expr], ast.expr]) -> Callable[[ast.Call], ast.Call]:
62
- def workhorse(node: ast.Call) -> ast.Call:
63
- node.func = action(node.func)
64
- return node
65
- return workhorse
66
-
67
- @staticmethod
68
- def funcDOTidAttribute(action: Callable[[ast_Identifier], Any]) -> Callable[[ImaCallToName], ImaCallToName]:
69
- def workhorse(node: ImaCallToName) -> ImaCallToName:
70
- node.func = grab.idAttribute(action)(node.func)
71
- return node
72
- return workhorse
73
-
74
- @staticmethod
75
- def idAttribute(action: Callable[[ast_Identifier], ast_Identifier]) -> Callable[[ast.Name], ast.Name]:
76
- def workhorse(node: ast.Name) -> ast.Name:
77
- node.id = action(node.id)
78
- return node
79
- return workhorse
80
-
81
- @staticmethod
82
- def leftAttribute(action: Callable[[ast.expr], ast.expr]) -> Callable[[ast.BinOp | ast.Compare], ast.BinOp | ast.Compare]:
83
- def workhorse(node: ast.BinOp | ast.Compare) -> ast.BinOp | ast.Compare:
84
- node.left = action(node.left)
85
- return node
86
- return workhorse
87
-
88
- @staticmethod
89
- def opsAttribute(action: Callable[[list[ast.cmpop]], list[ast.cmpop]]) -> Callable[[ast.Compare], ast.Compare]:
90
- def workhorse(node: ast.Compare) -> ast.Compare:
91
- node.ops = action(node.ops)
92
- return node
93
- return workhorse
94
-
95
- @staticmethod
96
- def testAttribute(action: Callable[[ast.expr], ast.expr]) -> Callable[[ast.Assert | ast.If | ast.IfExp | ast.While], ast.Assert | ast.If | ast.IfExp | ast.While]:
97
- def workhorse(node: ast.Assert | ast.If | ast.IfExp | ast.While) -> ast.Assert | ast.If | ast.IfExp | ast.While:
98
- node.test = action(node.test)
99
- return node
100
- return workhorse
101
-
102
- @staticmethod
103
- def valueAttribute(action: Callable[[Any], Any]) -> Callable[[astClassHasDOTvalue], astClassHasDOTvalue]:
104
- def workhorse(node: astClassHasDOTvalue) -> astClassHasDOTvalue:
105
- node.value = action(node.value)
106
- return node
107
- return workhorse
108
-
109
- class Then:
110
- """
111
- Provide action functions that specify what to do with AST nodes that match predicates.
112
-
113
- The Then class contains static methods that generate action functions used with NodeChanger and NodeTourist to
114
- transform or extract information from AST nodes that match specific predicates. These actions include node
115
- replacement, insertion, extraction, and collection operations.
116
-
117
- When paired with predicates from the ifThis class, Then methods complete the pattern-matching-and-action workflow
118
- for AST manipulation.
119
- """
120
- @staticmethod
121
- def appendTo(listOfAny: list[Any]) -> Callable[[ast.AST | ast_Identifier], ast.AST | ast_Identifier]:
122
- def workhorse(node: ast.AST | ast_Identifier) -> ast.AST | ast_Identifier:
123
- listOfAny.append(node)
124
- return node
125
- return workhorse
126
-
127
- @staticmethod
128
- def extractIt(node: NodeORattribute) -> NodeORattribute:
129
- return node
130
-
131
- @staticmethod
132
- def insertThisAbove(list_astAST: Sequence[ast.AST]) -> Callable[[ast.AST], Sequence[ast.AST]]:
133
- return lambda aboveMe: [*list_astAST, aboveMe]
134
-
135
- @staticmethod
136
- def insertThisBelow(list_astAST: Sequence[ast.AST]) -> Callable[[ast.AST], Sequence[ast.AST]]:
137
- return lambda belowMe: [belowMe, *list_astAST]
138
-
139
- @staticmethod
140
- def removeIt(_removeMe: ast.AST) -> None:
141
- return None
142
-
143
- @staticmethod
144
- def replaceWith(astAST: NodeORattribute) -> Callable[[NodeORattribute], NodeORattribute]:
145
- return lambda _replaceMe: astAST
146
-
147
- @staticmethod
148
- def updateKeyValueIn(key: Callable[..., Any], value: Callable[..., Any], dictionary: dict[Any, Any]) -> Callable[[ast.AST], dict[Any, Any]]:
149
- def workhorse(node: ast.AST) -> dict[Any, Any]:
150
- dictionary.setdefault(key(node), value(node))
151
- return dictionary
152
- return workhorse