astToolkit 0.3.4__tar.gz → 0.3.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {asttoolkit-0.3.4 → asttoolkit-0.3.5}/PKG-INFO +1 -3
- {asttoolkit-0.3.4 → asttoolkit-0.3.5}/astToolkit/_astTypes.py +16 -3
- asttoolkit-0.3.5/astToolkit/_joinClassmethod.py +586 -0
- {asttoolkit-0.3.4 → asttoolkit-0.3.5}/astToolkit/_theSSOT.py +4 -4
- {asttoolkit-0.3.4 → asttoolkit-0.3.5}/astToolkit/_toolBe.py +11 -11
- {asttoolkit-0.3.4 → asttoolkit-0.3.5}/astToolkit/_toolClassIsAndAttribute.py +13 -13
- {asttoolkit-0.3.4 → asttoolkit-0.3.5}/astToolkit/_toolDOT.py +36 -37
- {asttoolkit-0.3.4 → asttoolkit-0.3.5}/astToolkit/_toolGrab.py +23 -24
- {asttoolkit-0.3.4 → asttoolkit-0.3.5}/astToolkit/_toolMake.py +134 -119
- {asttoolkit-0.3.4 → asttoolkit-0.3.5}/astToolkit.egg-info/PKG-INFO +1 -3
- {asttoolkit-0.3.4 → asttoolkit-0.3.5}/pyproject.toml +1 -3
- asttoolkit-0.3.4/astToolkit/_joinClassmethod.py +0 -1260
- {asttoolkit-0.3.4 → asttoolkit-0.3.5}/LICENSE +0 -0
- {asttoolkit-0.3.4 → asttoolkit-0.3.5}/README.md +0 -0
- {asttoolkit-0.3.4 → asttoolkit-0.3.5}/astToolkit/__init__.py +0 -0
- {asttoolkit-0.3.4 → asttoolkit-0.3.5}/astToolkit/_dumpFunctionDef.py +0 -0
- {asttoolkit-0.3.4 → asttoolkit-0.3.5}/astToolkit/_toolIfThis.py +0 -0
- {asttoolkit-0.3.4 → asttoolkit-0.3.5}/astToolkit/_toolThen.py +0 -0
- {asttoolkit-0.3.4 → asttoolkit-0.3.5}/astToolkit/_toolkitAST.py +0 -0
- {asttoolkit-0.3.4 → asttoolkit-0.3.5}/astToolkit/_toolkitContainers.py +0 -0
- {asttoolkit-0.3.4 → asttoolkit-0.3.5}/astToolkit/_toolkitNodeVisitor.py +0 -0
- {asttoolkit-0.3.4 → asttoolkit-0.3.5}/astToolkit/_types.py +0 -0
- {asttoolkit-0.3.4 → asttoolkit-0.3.5}/astToolkit/py.typed +0 -0
- {asttoolkit-0.3.4 → asttoolkit-0.3.5}/astToolkit/transformationTools.py +0 -0
- {asttoolkit-0.3.4 → asttoolkit-0.3.5}/astToolkit.egg-info/SOURCES.txt +0 -0
- {asttoolkit-0.3.4 → asttoolkit-0.3.5}/astToolkit.egg-info/dependency_links.txt +0 -0
- {asttoolkit-0.3.4 → asttoolkit-0.3.5}/astToolkit.egg-info/requires.txt +0 -0
- {asttoolkit-0.3.4 → asttoolkit-0.3.5}/astToolkit.egg-info/top_level.txt +0 -0
- {asttoolkit-0.3.4 → asttoolkit-0.3.5}/setup.cfg +0 -0
- {asttoolkit-0.3.4 → asttoolkit-0.3.5}/tests/conftest.py +0 -0
- {asttoolkit-0.3.4 → asttoolkit-0.3.5}/tests/test_basic.py +0 -0
- {asttoolkit-0.3.4 → asttoolkit-0.3.5}/tests/test_joinClassmethod.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: astToolkit
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.5
|
|
4
4
|
Summary: A powerfully composable, type-safe toolkit for Python abstract syntax tree (AST) manipulation, analysis, transformation, and code generation with a layered architecture designed for building sophisticated code processing assembly-lines.
|
|
5
5
|
Author-email: Hunter Hogan <HunterHogan@pm.me>
|
|
6
6
|
License: CC-BY-NC-4.0
|
|
@@ -17,8 +17,6 @@ Classifier: Natural Language :: English
|
|
|
17
17
|
Classifier: Operating System :: OS Independent
|
|
18
18
|
Classifier: Programming Language :: Python
|
|
19
19
|
Classifier: Programming Language :: Python :: 3
|
|
20
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
22
20
|
Classifier: Programming Language :: Python :: 3.12
|
|
23
21
|
Classifier: Programming Language :: Python :: 3.13
|
|
24
22
|
Classifier: Typing :: Typed
|
|
@@ -1,19 +1,32 @@
|
|
|
1
1
|
"""This file is generated automatically, so changes to this file will be lost."""
|
|
2
|
+
from types import EllipsisType, NotImplementedType
|
|
2
3
|
from typing import Any, TypeAlias as typing_TypeAlias, TypedDict, TypeVar as typing_TypeVar
|
|
3
4
|
import ast
|
|
4
5
|
import sys
|
|
6
|
+
|
|
5
7
|
intORstr: typing_TypeAlias = Any
|
|
6
8
|
intORstrORtype_params: typing_TypeAlias = Any
|
|
7
9
|
intORtype_params: typing_TypeAlias = Any
|
|
10
|
+
_Scalar: typing_TypeAlias = bool | bytes | complex | EllipsisType | float | int | None | NotImplementedType | range | str
|
|
11
|
+
ScalarOrContainerOfScalar: typing_TypeAlias = _Scalar | frozenset['ScalarOrContainerOfScalar'] | tuple['ScalarOrContainerOfScalar', ...]
|
|
8
12
|
木 = typing_TypeVar('木', bound=ast.AST, covariant=True)
|
|
9
13
|
个 = typing_TypeVar('个', covariant=True)
|
|
10
14
|
个return = typing_TypeVar('个return', covariant=True)
|
|
11
15
|
|
|
12
|
-
class
|
|
16
|
+
class _attributes(TypedDict, total=False):
|
|
13
17
|
lineno: int
|
|
14
18
|
col_offset: int
|
|
19
|
+
|
|
20
|
+
class ast_attributes(_attributes, total=False):
|
|
15
21
|
end_lineno: int | None
|
|
16
22
|
end_col_offset: int | None
|
|
23
|
+
|
|
24
|
+
class ast_attributes_int(_attributes, total=False):
|
|
25
|
+
end_lineno: int
|
|
26
|
+
end_col_offset: int
|
|
27
|
+
|
|
28
|
+
class ast_attributes_type_comment(ast_attributes, total=False):
|
|
29
|
+
type_comment: str | None
|
|
17
30
|
hasDOTannotation_expr: typing_TypeAlias = ast.AnnAssign
|
|
18
31
|
hasDOTannotation_exprOrNone: typing_TypeAlias = ast.arg
|
|
19
32
|
hasDOTannotation: typing_TypeAlias = hasDOTannotation_expr | hasDOTannotation_exprOrNone
|
|
@@ -117,10 +130,10 @@ hasDOTtype_comment: typing_TypeAlias = ast.arg | ast.Assign | ast.AsyncFor | ast
|
|
|
117
130
|
hasDOTtype_ignores: typing_TypeAlias = ast.Module
|
|
118
131
|
hasDOTtype_params: typing_TypeAlias = ast.AsyncFunctionDef | ast.ClassDef | ast.FunctionDef | ast.TypeAlias
|
|
119
132
|
hasDOTupper: typing_TypeAlias = ast.Slice
|
|
120
|
-
|
|
133
|
+
hasDOTvalue_ScalarOrContainerOfScalar: typing_TypeAlias = ast.Constant
|
|
121
134
|
hasDOTvalue_boolOrNone: typing_TypeAlias = ast.MatchSingleton
|
|
122
135
|
hasDOTvalue_expr: typing_TypeAlias = ast.Assign | ast.Attribute | ast.AugAssign | ast.Await | ast.DictComp | ast.Expr | ast.FormattedValue | ast.keyword | ast.MatchValue | ast.NamedExpr | ast.Starred | ast.Subscript | ast.TypeAlias | ast.YieldFrom
|
|
123
136
|
hasDOTvalue_exprOrNone: typing_TypeAlias = ast.AnnAssign | ast.Return | ast.Yield
|
|
124
|
-
hasDOTvalue: typing_TypeAlias =
|
|
137
|
+
hasDOTvalue: typing_TypeAlias = hasDOTvalue_ScalarOrContainerOfScalar | hasDOTvalue_boolOrNone | hasDOTvalue_expr | hasDOTvalue_exprOrNone
|
|
125
138
|
hasDOTvalues: typing_TypeAlias = ast.BoolOp | ast.Dict | ast.JoinedStr
|
|
126
139
|
hasDOTvararg: typing_TypeAlias = ast.arguments
|
|
@@ -0,0 +1,586 @@
|
|
|
1
|
+
"""This file is generated automatically, so changes to this file will be lost."""
|
|
2
|
+
from astToolkit import ast_attributes, Make
|
|
3
|
+
from collections.abc import Iterable
|
|
4
|
+
from typing import Unpack
|
|
5
|
+
import ast
|
|
6
|
+
|
|
7
|
+
def operatorJoinMethod(ast_operator: type[ast.operator], expressions: Iterable[ast.expr], **keywordArguments: Unpack[ast_attributes]) -> ast.expr:
|
|
8
|
+
listExpressions: list[ast.expr] = list(expressions)
|
|
9
|
+
if not listExpressions:
|
|
10
|
+
listExpressions.append(Make.Constant('', **keywordArguments))
|
|
11
|
+
expressionsJoined: ast.expr = listExpressions[0]
|
|
12
|
+
for expression in listExpressions[1:]:
|
|
13
|
+
expressionsJoined = ast.BinOp(left=expressionsJoined, op=ast_operator(), right=expression, **keywordArguments)
|
|
14
|
+
return expressionsJoined
|
|
15
|
+
|
|
16
|
+
class Add(ast.Add):
|
|
17
|
+
"""Identical to the `ast` class but with a method, `join()`, that "joins" expressions using the `ast.BinOp` class."""
|
|
18
|
+
|
|
19
|
+
@classmethod
|
|
20
|
+
def join(cls, expressions: Iterable[ast.expr], **keywordArguments: Unpack[ast_attributes]) -> ast.expr:
|
|
21
|
+
"""
|
|
22
|
+
Create a single `ast.expr` from a collection of `ast.expr` by forming nested `ast.BinOp`
|
|
23
|
+
that are logically "joined" using the `ast.operator` subclass. Like str.join() but for AST expressions.
|
|
24
|
+
|
|
25
|
+
Parameters
|
|
26
|
+
----------
|
|
27
|
+
expressions : Iterable[ast.expr]
|
|
28
|
+
Collection of expressions to join.
|
|
29
|
+
**keywordArguments : ast._attributes
|
|
30
|
+
|
|
31
|
+
Returns
|
|
32
|
+
-------
|
|
33
|
+
joinedExpression : ast.expr
|
|
34
|
+
Single expression representing the joined expressions.
|
|
35
|
+
|
|
36
|
+
Examples
|
|
37
|
+
--------
|
|
38
|
+
Instead of manually constructing nested ast.BinOp structures:
|
|
39
|
+
```
|
|
40
|
+
ast.BinOp(
|
|
41
|
+
left=ast.BinOp(
|
|
42
|
+
left=ast.Name('Crosby')
|
|
43
|
+
, op=ast.BitOr()
|
|
44
|
+
, right=ast.Name('Stills'))
|
|
45
|
+
, op=ast.BitOr()
|
|
46
|
+
, right=ast.Name('Nash')
|
|
47
|
+
)
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Simply use:
|
|
51
|
+
```
|
|
52
|
+
astToolkit.BitOr().join([ast.Name('Crosby'), ast.Name('Stills'), ast.Name('Nash')])
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Both produce the same AST structure but the join() method eliminates the manual nesting.
|
|
56
|
+
Handles single expressions and empty iterables gracefully.
|
|
57
|
+
"""
|
|
58
|
+
return operatorJoinMethod(cls, expressions, **keywordArguments)
|
|
59
|
+
|
|
60
|
+
class BitAnd(ast.BitAnd):
|
|
61
|
+
"""Identical to the `ast` class but with a method, `join()`, that "joins" expressions using the `ast.BinOp` class."""
|
|
62
|
+
|
|
63
|
+
@classmethod
|
|
64
|
+
def join(cls, expressions: Iterable[ast.expr], **keywordArguments: Unpack[ast_attributes]) -> ast.expr:
|
|
65
|
+
"""
|
|
66
|
+
Create a single `ast.expr` from a collection of `ast.expr` by forming nested `ast.BinOp`
|
|
67
|
+
that are logically "joined" using the `ast.operator` subclass. Like str.join() but for AST expressions.
|
|
68
|
+
|
|
69
|
+
Parameters
|
|
70
|
+
----------
|
|
71
|
+
expressions : Iterable[ast.expr]
|
|
72
|
+
Collection of expressions to join.
|
|
73
|
+
**keywordArguments : ast._attributes
|
|
74
|
+
|
|
75
|
+
Returns
|
|
76
|
+
-------
|
|
77
|
+
joinedExpression : ast.expr
|
|
78
|
+
Single expression representing the joined expressions.
|
|
79
|
+
|
|
80
|
+
Examples
|
|
81
|
+
--------
|
|
82
|
+
Instead of manually constructing nested ast.BinOp structures:
|
|
83
|
+
```
|
|
84
|
+
ast.BinOp(
|
|
85
|
+
left=ast.BinOp(
|
|
86
|
+
left=ast.Name('Crosby')
|
|
87
|
+
, op=ast.BitOr()
|
|
88
|
+
, right=ast.Name('Stills'))
|
|
89
|
+
, op=ast.BitOr()
|
|
90
|
+
, right=ast.Name('Nash')
|
|
91
|
+
)
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Simply use:
|
|
95
|
+
```
|
|
96
|
+
astToolkit.BitOr().join([ast.Name('Crosby'), ast.Name('Stills'), ast.Name('Nash')])
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Both produce the same AST structure but the join() method eliminates the manual nesting.
|
|
100
|
+
Handles single expressions and empty iterables gracefully.
|
|
101
|
+
"""
|
|
102
|
+
return operatorJoinMethod(cls, expressions, **keywordArguments)
|
|
103
|
+
|
|
104
|
+
class BitOr(ast.BitOr):
|
|
105
|
+
"""Identical to the `ast` class but with a method, `join()`, that "joins" expressions using the `ast.BinOp` class."""
|
|
106
|
+
|
|
107
|
+
@classmethod
|
|
108
|
+
def join(cls, expressions: Iterable[ast.expr], **keywordArguments: Unpack[ast_attributes]) -> ast.expr:
|
|
109
|
+
"""
|
|
110
|
+
Create a single `ast.expr` from a collection of `ast.expr` by forming nested `ast.BinOp`
|
|
111
|
+
that are logically "joined" using the `ast.operator` subclass. Like str.join() but for AST expressions.
|
|
112
|
+
|
|
113
|
+
Parameters
|
|
114
|
+
----------
|
|
115
|
+
expressions : Iterable[ast.expr]
|
|
116
|
+
Collection of expressions to join.
|
|
117
|
+
**keywordArguments : ast._attributes
|
|
118
|
+
|
|
119
|
+
Returns
|
|
120
|
+
-------
|
|
121
|
+
joinedExpression : ast.expr
|
|
122
|
+
Single expression representing the joined expressions.
|
|
123
|
+
|
|
124
|
+
Examples
|
|
125
|
+
--------
|
|
126
|
+
Instead of manually constructing nested ast.BinOp structures:
|
|
127
|
+
```
|
|
128
|
+
ast.BinOp(
|
|
129
|
+
left=ast.BinOp(
|
|
130
|
+
left=ast.Name('Crosby')
|
|
131
|
+
, op=ast.BitOr()
|
|
132
|
+
, right=ast.Name('Stills'))
|
|
133
|
+
, op=ast.BitOr()
|
|
134
|
+
, right=ast.Name('Nash')
|
|
135
|
+
)
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Simply use:
|
|
139
|
+
```
|
|
140
|
+
astToolkit.BitOr().join([ast.Name('Crosby'), ast.Name('Stills'), ast.Name('Nash')])
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Both produce the same AST structure but the join() method eliminates the manual nesting.
|
|
144
|
+
Handles single expressions and empty iterables gracefully.
|
|
145
|
+
"""
|
|
146
|
+
return operatorJoinMethod(cls, expressions, **keywordArguments)
|
|
147
|
+
|
|
148
|
+
class BitXor(ast.BitXor):
|
|
149
|
+
"""Identical to the `ast` class but with a method, `join()`, that "joins" expressions using the `ast.BinOp` class."""
|
|
150
|
+
|
|
151
|
+
@classmethod
|
|
152
|
+
def join(cls, expressions: Iterable[ast.expr], **keywordArguments: Unpack[ast_attributes]) -> ast.expr:
|
|
153
|
+
"""
|
|
154
|
+
Create a single `ast.expr` from a collection of `ast.expr` by forming nested `ast.BinOp`
|
|
155
|
+
that are logically "joined" using the `ast.operator` subclass. Like str.join() but for AST expressions.
|
|
156
|
+
|
|
157
|
+
Parameters
|
|
158
|
+
----------
|
|
159
|
+
expressions : Iterable[ast.expr]
|
|
160
|
+
Collection of expressions to join.
|
|
161
|
+
**keywordArguments : ast._attributes
|
|
162
|
+
|
|
163
|
+
Returns
|
|
164
|
+
-------
|
|
165
|
+
joinedExpression : ast.expr
|
|
166
|
+
Single expression representing the joined expressions.
|
|
167
|
+
|
|
168
|
+
Examples
|
|
169
|
+
--------
|
|
170
|
+
Instead of manually constructing nested ast.BinOp structures:
|
|
171
|
+
```
|
|
172
|
+
ast.BinOp(
|
|
173
|
+
left=ast.BinOp(
|
|
174
|
+
left=ast.Name('Crosby')
|
|
175
|
+
, op=ast.BitOr()
|
|
176
|
+
, right=ast.Name('Stills'))
|
|
177
|
+
, op=ast.BitOr()
|
|
178
|
+
, right=ast.Name('Nash')
|
|
179
|
+
)
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
Simply use:
|
|
183
|
+
```
|
|
184
|
+
astToolkit.BitOr().join([ast.Name('Crosby'), ast.Name('Stills'), ast.Name('Nash')])
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
Both produce the same AST structure but the join() method eliminates the manual nesting.
|
|
188
|
+
Handles single expressions and empty iterables gracefully.
|
|
189
|
+
"""
|
|
190
|
+
return operatorJoinMethod(cls, expressions, **keywordArguments)
|
|
191
|
+
|
|
192
|
+
class Div(ast.Div):
|
|
193
|
+
"""Identical to the `ast` class but with a method, `join()`, that "joins" expressions using the `ast.BinOp` class."""
|
|
194
|
+
|
|
195
|
+
@classmethod
|
|
196
|
+
def join(cls, expressions: Iterable[ast.expr], **keywordArguments: Unpack[ast_attributes]) -> ast.expr:
|
|
197
|
+
"""
|
|
198
|
+
Create a single `ast.expr` from a collection of `ast.expr` by forming nested `ast.BinOp`
|
|
199
|
+
that are logically "joined" using the `ast.operator` subclass. Like str.join() but for AST expressions.
|
|
200
|
+
|
|
201
|
+
Parameters
|
|
202
|
+
----------
|
|
203
|
+
expressions : Iterable[ast.expr]
|
|
204
|
+
Collection of expressions to join.
|
|
205
|
+
**keywordArguments : ast._attributes
|
|
206
|
+
|
|
207
|
+
Returns
|
|
208
|
+
-------
|
|
209
|
+
joinedExpression : ast.expr
|
|
210
|
+
Single expression representing the joined expressions.
|
|
211
|
+
|
|
212
|
+
Examples
|
|
213
|
+
--------
|
|
214
|
+
Instead of manually constructing nested ast.BinOp structures:
|
|
215
|
+
```
|
|
216
|
+
ast.BinOp(
|
|
217
|
+
left=ast.BinOp(
|
|
218
|
+
left=ast.Name('Crosby')
|
|
219
|
+
, op=ast.BitOr()
|
|
220
|
+
, right=ast.Name('Stills'))
|
|
221
|
+
, op=ast.BitOr()
|
|
222
|
+
, right=ast.Name('Nash')
|
|
223
|
+
)
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
Simply use:
|
|
227
|
+
```
|
|
228
|
+
astToolkit.BitOr().join([ast.Name('Crosby'), ast.Name('Stills'), ast.Name('Nash')])
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
Both produce the same AST structure but the join() method eliminates the manual nesting.
|
|
232
|
+
Handles single expressions and empty iterables gracefully.
|
|
233
|
+
"""
|
|
234
|
+
return operatorJoinMethod(cls, expressions, **keywordArguments)
|
|
235
|
+
|
|
236
|
+
class FloorDiv(ast.FloorDiv):
|
|
237
|
+
"""Identical to the `ast` class but with a method, `join()`, that "joins" expressions using the `ast.BinOp` class."""
|
|
238
|
+
|
|
239
|
+
@classmethod
|
|
240
|
+
def join(cls, expressions: Iterable[ast.expr], **keywordArguments: Unpack[ast_attributes]) -> ast.expr:
|
|
241
|
+
"""
|
|
242
|
+
Create a single `ast.expr` from a collection of `ast.expr` by forming nested `ast.BinOp`
|
|
243
|
+
that are logically "joined" using the `ast.operator` subclass. Like str.join() but for AST expressions.
|
|
244
|
+
|
|
245
|
+
Parameters
|
|
246
|
+
----------
|
|
247
|
+
expressions : Iterable[ast.expr]
|
|
248
|
+
Collection of expressions to join.
|
|
249
|
+
**keywordArguments : ast._attributes
|
|
250
|
+
|
|
251
|
+
Returns
|
|
252
|
+
-------
|
|
253
|
+
joinedExpression : ast.expr
|
|
254
|
+
Single expression representing the joined expressions.
|
|
255
|
+
|
|
256
|
+
Examples
|
|
257
|
+
--------
|
|
258
|
+
Instead of manually constructing nested ast.BinOp structures:
|
|
259
|
+
```
|
|
260
|
+
ast.BinOp(
|
|
261
|
+
left=ast.BinOp(
|
|
262
|
+
left=ast.Name('Crosby')
|
|
263
|
+
, op=ast.BitOr()
|
|
264
|
+
, right=ast.Name('Stills'))
|
|
265
|
+
, op=ast.BitOr()
|
|
266
|
+
, right=ast.Name('Nash')
|
|
267
|
+
)
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
Simply use:
|
|
271
|
+
```
|
|
272
|
+
astToolkit.BitOr().join([ast.Name('Crosby'), ast.Name('Stills'), ast.Name('Nash')])
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
Both produce the same AST structure but the join() method eliminates the manual nesting.
|
|
276
|
+
Handles single expressions and empty iterables gracefully.
|
|
277
|
+
"""
|
|
278
|
+
return operatorJoinMethod(cls, expressions, **keywordArguments)
|
|
279
|
+
|
|
280
|
+
class LShift(ast.LShift):
|
|
281
|
+
"""Identical to the `ast` class but with a method, `join()`, that "joins" expressions using the `ast.BinOp` class."""
|
|
282
|
+
|
|
283
|
+
@classmethod
|
|
284
|
+
def join(cls, expressions: Iterable[ast.expr], **keywordArguments: Unpack[ast_attributes]) -> ast.expr:
|
|
285
|
+
"""
|
|
286
|
+
Create a single `ast.expr` from a collection of `ast.expr` by forming nested `ast.BinOp`
|
|
287
|
+
that are logically "joined" using the `ast.operator` subclass. Like str.join() but for AST expressions.
|
|
288
|
+
|
|
289
|
+
Parameters
|
|
290
|
+
----------
|
|
291
|
+
expressions : Iterable[ast.expr]
|
|
292
|
+
Collection of expressions to join.
|
|
293
|
+
**keywordArguments : ast._attributes
|
|
294
|
+
|
|
295
|
+
Returns
|
|
296
|
+
-------
|
|
297
|
+
joinedExpression : ast.expr
|
|
298
|
+
Single expression representing the joined expressions.
|
|
299
|
+
|
|
300
|
+
Examples
|
|
301
|
+
--------
|
|
302
|
+
Instead of manually constructing nested ast.BinOp structures:
|
|
303
|
+
```
|
|
304
|
+
ast.BinOp(
|
|
305
|
+
left=ast.BinOp(
|
|
306
|
+
left=ast.Name('Crosby')
|
|
307
|
+
, op=ast.BitOr()
|
|
308
|
+
, right=ast.Name('Stills'))
|
|
309
|
+
, op=ast.BitOr()
|
|
310
|
+
, right=ast.Name('Nash')
|
|
311
|
+
)
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
Simply use:
|
|
315
|
+
```
|
|
316
|
+
astToolkit.BitOr().join([ast.Name('Crosby'), ast.Name('Stills'), ast.Name('Nash')])
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
Both produce the same AST structure but the join() method eliminates the manual nesting.
|
|
320
|
+
Handles single expressions and empty iterables gracefully.
|
|
321
|
+
"""
|
|
322
|
+
return operatorJoinMethod(cls, expressions, **keywordArguments)
|
|
323
|
+
|
|
324
|
+
class MatMult(ast.MatMult):
|
|
325
|
+
"""Identical to the `ast` class but with a method, `join()`, that "joins" expressions using the `ast.BinOp` class."""
|
|
326
|
+
|
|
327
|
+
@classmethod
|
|
328
|
+
def join(cls, expressions: Iterable[ast.expr], **keywordArguments: Unpack[ast_attributes]) -> ast.expr:
|
|
329
|
+
"""
|
|
330
|
+
Create a single `ast.expr` from a collection of `ast.expr` by forming nested `ast.BinOp`
|
|
331
|
+
that are logically "joined" using the `ast.operator` subclass. Like str.join() but for AST expressions.
|
|
332
|
+
|
|
333
|
+
Parameters
|
|
334
|
+
----------
|
|
335
|
+
expressions : Iterable[ast.expr]
|
|
336
|
+
Collection of expressions to join.
|
|
337
|
+
**keywordArguments : ast._attributes
|
|
338
|
+
|
|
339
|
+
Returns
|
|
340
|
+
-------
|
|
341
|
+
joinedExpression : ast.expr
|
|
342
|
+
Single expression representing the joined expressions.
|
|
343
|
+
|
|
344
|
+
Examples
|
|
345
|
+
--------
|
|
346
|
+
Instead of manually constructing nested ast.BinOp structures:
|
|
347
|
+
```
|
|
348
|
+
ast.BinOp(
|
|
349
|
+
left=ast.BinOp(
|
|
350
|
+
left=ast.Name('Crosby')
|
|
351
|
+
, op=ast.BitOr()
|
|
352
|
+
, right=ast.Name('Stills'))
|
|
353
|
+
, op=ast.BitOr()
|
|
354
|
+
, right=ast.Name('Nash')
|
|
355
|
+
)
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
Simply use:
|
|
359
|
+
```
|
|
360
|
+
astToolkit.BitOr().join([ast.Name('Crosby'), ast.Name('Stills'), ast.Name('Nash')])
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
Both produce the same AST structure but the join() method eliminates the manual nesting.
|
|
364
|
+
Handles single expressions and empty iterables gracefully.
|
|
365
|
+
"""
|
|
366
|
+
return operatorJoinMethod(cls, expressions, **keywordArguments)
|
|
367
|
+
|
|
368
|
+
class Mod(ast.Mod):
|
|
369
|
+
"""Identical to the `ast` class but with a method, `join()`, that "joins" expressions using the `ast.BinOp` class."""
|
|
370
|
+
|
|
371
|
+
@classmethod
|
|
372
|
+
def join(cls, expressions: Iterable[ast.expr], **keywordArguments: Unpack[ast_attributes]) -> ast.expr:
|
|
373
|
+
"""
|
|
374
|
+
Create a single `ast.expr` from a collection of `ast.expr` by forming nested `ast.BinOp`
|
|
375
|
+
that are logically "joined" using the `ast.operator` subclass. Like str.join() but for AST expressions.
|
|
376
|
+
|
|
377
|
+
Parameters
|
|
378
|
+
----------
|
|
379
|
+
expressions : Iterable[ast.expr]
|
|
380
|
+
Collection of expressions to join.
|
|
381
|
+
**keywordArguments : ast._attributes
|
|
382
|
+
|
|
383
|
+
Returns
|
|
384
|
+
-------
|
|
385
|
+
joinedExpression : ast.expr
|
|
386
|
+
Single expression representing the joined expressions.
|
|
387
|
+
|
|
388
|
+
Examples
|
|
389
|
+
--------
|
|
390
|
+
Instead of manually constructing nested ast.BinOp structures:
|
|
391
|
+
```
|
|
392
|
+
ast.BinOp(
|
|
393
|
+
left=ast.BinOp(
|
|
394
|
+
left=ast.Name('Crosby')
|
|
395
|
+
, op=ast.BitOr()
|
|
396
|
+
, right=ast.Name('Stills'))
|
|
397
|
+
, op=ast.BitOr()
|
|
398
|
+
, right=ast.Name('Nash')
|
|
399
|
+
)
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
Simply use:
|
|
403
|
+
```
|
|
404
|
+
astToolkit.BitOr().join([ast.Name('Crosby'), ast.Name('Stills'), ast.Name('Nash')])
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
Both produce the same AST structure but the join() method eliminates the manual nesting.
|
|
408
|
+
Handles single expressions and empty iterables gracefully.
|
|
409
|
+
"""
|
|
410
|
+
return operatorJoinMethod(cls, expressions, **keywordArguments)
|
|
411
|
+
|
|
412
|
+
class Mult(ast.Mult):
|
|
413
|
+
"""Identical to the `ast` class but with a method, `join()`, that "joins" expressions using the `ast.BinOp` class."""
|
|
414
|
+
|
|
415
|
+
@classmethod
|
|
416
|
+
def join(cls, expressions: Iterable[ast.expr], **keywordArguments: Unpack[ast_attributes]) -> ast.expr:
|
|
417
|
+
"""
|
|
418
|
+
Create a single `ast.expr` from a collection of `ast.expr` by forming nested `ast.BinOp`
|
|
419
|
+
that are logically "joined" using the `ast.operator` subclass. Like str.join() but for AST expressions.
|
|
420
|
+
|
|
421
|
+
Parameters
|
|
422
|
+
----------
|
|
423
|
+
expressions : Iterable[ast.expr]
|
|
424
|
+
Collection of expressions to join.
|
|
425
|
+
**keywordArguments : ast._attributes
|
|
426
|
+
|
|
427
|
+
Returns
|
|
428
|
+
-------
|
|
429
|
+
joinedExpression : ast.expr
|
|
430
|
+
Single expression representing the joined expressions.
|
|
431
|
+
|
|
432
|
+
Examples
|
|
433
|
+
--------
|
|
434
|
+
Instead of manually constructing nested ast.BinOp structures:
|
|
435
|
+
```
|
|
436
|
+
ast.BinOp(
|
|
437
|
+
left=ast.BinOp(
|
|
438
|
+
left=ast.Name('Crosby')
|
|
439
|
+
, op=ast.BitOr()
|
|
440
|
+
, right=ast.Name('Stills'))
|
|
441
|
+
, op=ast.BitOr()
|
|
442
|
+
, right=ast.Name('Nash')
|
|
443
|
+
)
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
Simply use:
|
|
447
|
+
```
|
|
448
|
+
astToolkit.BitOr().join([ast.Name('Crosby'), ast.Name('Stills'), ast.Name('Nash')])
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
Both produce the same AST structure but the join() method eliminates the manual nesting.
|
|
452
|
+
Handles single expressions and empty iterables gracefully.
|
|
453
|
+
"""
|
|
454
|
+
return operatorJoinMethod(cls, expressions, **keywordArguments)
|
|
455
|
+
|
|
456
|
+
class Pow(ast.Pow):
|
|
457
|
+
"""Identical to the `ast` class but with a method, `join()`, that "joins" expressions using the `ast.BinOp` class."""
|
|
458
|
+
|
|
459
|
+
@classmethod
|
|
460
|
+
def join(cls, expressions: Iterable[ast.expr], **keywordArguments: Unpack[ast_attributes]) -> ast.expr:
|
|
461
|
+
"""
|
|
462
|
+
Create a single `ast.expr` from a collection of `ast.expr` by forming nested `ast.BinOp`
|
|
463
|
+
that are logically "joined" using the `ast.operator` subclass. Like str.join() but for AST expressions.
|
|
464
|
+
|
|
465
|
+
Parameters
|
|
466
|
+
----------
|
|
467
|
+
expressions : Iterable[ast.expr]
|
|
468
|
+
Collection of expressions to join.
|
|
469
|
+
**keywordArguments : ast._attributes
|
|
470
|
+
|
|
471
|
+
Returns
|
|
472
|
+
-------
|
|
473
|
+
joinedExpression : ast.expr
|
|
474
|
+
Single expression representing the joined expressions.
|
|
475
|
+
|
|
476
|
+
Examples
|
|
477
|
+
--------
|
|
478
|
+
Instead of manually constructing nested ast.BinOp structures:
|
|
479
|
+
```
|
|
480
|
+
ast.BinOp(
|
|
481
|
+
left=ast.BinOp(
|
|
482
|
+
left=ast.Name('Crosby')
|
|
483
|
+
, op=ast.BitOr()
|
|
484
|
+
, right=ast.Name('Stills'))
|
|
485
|
+
, op=ast.BitOr()
|
|
486
|
+
, right=ast.Name('Nash')
|
|
487
|
+
)
|
|
488
|
+
```
|
|
489
|
+
|
|
490
|
+
Simply use:
|
|
491
|
+
```
|
|
492
|
+
astToolkit.BitOr().join([ast.Name('Crosby'), ast.Name('Stills'), ast.Name('Nash')])
|
|
493
|
+
```
|
|
494
|
+
|
|
495
|
+
Both produce the same AST structure but the join() method eliminates the manual nesting.
|
|
496
|
+
Handles single expressions and empty iterables gracefully.
|
|
497
|
+
"""
|
|
498
|
+
return operatorJoinMethod(cls, expressions, **keywordArguments)
|
|
499
|
+
|
|
500
|
+
class RShift(ast.RShift):
|
|
501
|
+
"""Identical to the `ast` class but with a method, `join()`, that "joins" expressions using the `ast.BinOp` class."""
|
|
502
|
+
|
|
503
|
+
@classmethod
|
|
504
|
+
def join(cls, expressions: Iterable[ast.expr], **keywordArguments: Unpack[ast_attributes]) -> ast.expr:
|
|
505
|
+
"""
|
|
506
|
+
Create a single `ast.expr` from a collection of `ast.expr` by forming nested `ast.BinOp`
|
|
507
|
+
that are logically "joined" using the `ast.operator` subclass. Like str.join() but for AST expressions.
|
|
508
|
+
|
|
509
|
+
Parameters
|
|
510
|
+
----------
|
|
511
|
+
expressions : Iterable[ast.expr]
|
|
512
|
+
Collection of expressions to join.
|
|
513
|
+
**keywordArguments : ast._attributes
|
|
514
|
+
|
|
515
|
+
Returns
|
|
516
|
+
-------
|
|
517
|
+
joinedExpression : ast.expr
|
|
518
|
+
Single expression representing the joined expressions.
|
|
519
|
+
|
|
520
|
+
Examples
|
|
521
|
+
--------
|
|
522
|
+
Instead of manually constructing nested ast.BinOp structures:
|
|
523
|
+
```
|
|
524
|
+
ast.BinOp(
|
|
525
|
+
left=ast.BinOp(
|
|
526
|
+
left=ast.Name('Crosby')
|
|
527
|
+
, op=ast.BitOr()
|
|
528
|
+
, right=ast.Name('Stills'))
|
|
529
|
+
, op=ast.BitOr()
|
|
530
|
+
, right=ast.Name('Nash')
|
|
531
|
+
)
|
|
532
|
+
```
|
|
533
|
+
|
|
534
|
+
Simply use:
|
|
535
|
+
```
|
|
536
|
+
astToolkit.BitOr().join([ast.Name('Crosby'), ast.Name('Stills'), ast.Name('Nash')])
|
|
537
|
+
```
|
|
538
|
+
|
|
539
|
+
Both produce the same AST structure but the join() method eliminates the manual nesting.
|
|
540
|
+
Handles single expressions and empty iterables gracefully.
|
|
541
|
+
"""
|
|
542
|
+
return operatorJoinMethod(cls, expressions, **keywordArguments)
|
|
543
|
+
|
|
544
|
+
class Sub(ast.Sub):
|
|
545
|
+
"""Identical to the `ast` class but with a method, `join()`, that "joins" expressions using the `ast.BinOp` class."""
|
|
546
|
+
|
|
547
|
+
@classmethod
|
|
548
|
+
def join(cls, expressions: Iterable[ast.expr], **keywordArguments: Unpack[ast_attributes]) -> ast.expr:
|
|
549
|
+
"""
|
|
550
|
+
Create a single `ast.expr` from a collection of `ast.expr` by forming nested `ast.BinOp`
|
|
551
|
+
that are logically "joined" using the `ast.operator` subclass. Like str.join() but for AST expressions.
|
|
552
|
+
|
|
553
|
+
Parameters
|
|
554
|
+
----------
|
|
555
|
+
expressions : Iterable[ast.expr]
|
|
556
|
+
Collection of expressions to join.
|
|
557
|
+
**keywordArguments : ast._attributes
|
|
558
|
+
|
|
559
|
+
Returns
|
|
560
|
+
-------
|
|
561
|
+
joinedExpression : ast.expr
|
|
562
|
+
Single expression representing the joined expressions.
|
|
563
|
+
|
|
564
|
+
Examples
|
|
565
|
+
--------
|
|
566
|
+
Instead of manually constructing nested ast.BinOp structures:
|
|
567
|
+
```
|
|
568
|
+
ast.BinOp(
|
|
569
|
+
left=ast.BinOp(
|
|
570
|
+
left=ast.Name('Crosby')
|
|
571
|
+
, op=ast.BitOr()
|
|
572
|
+
, right=ast.Name('Stills'))
|
|
573
|
+
, op=ast.BitOr()
|
|
574
|
+
, right=ast.Name('Nash')
|
|
575
|
+
)
|
|
576
|
+
```
|
|
577
|
+
|
|
578
|
+
Simply use:
|
|
579
|
+
```
|
|
580
|
+
astToolkit.BitOr().join([ast.Name('Crosby'), ast.Name('Stills'), ast.Name('Nash')])
|
|
581
|
+
```
|
|
582
|
+
|
|
583
|
+
Both produce the same AST structure but the join() method eliminates the manual nesting.
|
|
584
|
+
Handles single expressions and empty iterables gracefully.
|
|
585
|
+
"""
|
|
586
|
+
return operatorJoinMethod(cls, expressions, **keywordArguments)
|
|
@@ -6,12 +6,12 @@ import dataclasses
|
|
|
6
6
|
|
|
7
7
|
# TODO some of this can move to toolFactory because of the unusual nature of this package.
|
|
8
8
|
try:
|
|
9
|
-
|
|
9
|
+
identifierPackagePACKAGING: str = tomli_load(Path("pyproject.toml").open('rb'))["project"]["name"]
|
|
10
10
|
except Exception:
|
|
11
|
-
|
|
11
|
+
identifierPackagePACKAGING = "astToolkit"
|
|
12
12
|
|
|
13
13
|
def getPathPackageINSTALLING() -> Path:
|
|
14
|
-
pathPackage: Path = Path(inspect_getfile(importlib_import_module(
|
|
14
|
+
pathPackage: Path = Path(inspect_getfile(importlib_import_module(identifierPackagePACKAGING)))
|
|
15
15
|
if pathPackage.is_file():
|
|
16
16
|
pathPackage = pathPackage.parent
|
|
17
17
|
return pathPackage
|
|
@@ -22,7 +22,7 @@ class PackageSettings:
|
|
|
22
22
|
fileExtension: str = dataclasses.field(default='.py', metadata={'evaluateWhen': 'installing'})
|
|
23
23
|
"""Default file extension for generated code files."""
|
|
24
24
|
|
|
25
|
-
packageName: str = dataclasses.field(default =
|
|
25
|
+
packageName: str = dataclasses.field(default = identifierPackagePACKAGING, metadata={'evaluateWhen': 'packaging'})
|
|
26
26
|
"""Name of this package, used for import paths and configuration."""
|
|
27
27
|
|
|
28
28
|
pathPackage: Path = dataclasses.field(default_factory=getPathPackageINSTALLING, metadata={'evaluateWhen': 'installing'})
|