astToolkit 0.2.3__tar.gz → 0.3.0__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.
Files changed (41) hide show
  1. {asttoolkit-0.2.3 → asttoolkit-0.3.0}/PKG-INFO +22 -22
  2. {asttoolkit-0.2.3 → asttoolkit-0.3.0}/README.md +20 -20
  3. {asttoolkit-0.2.3 → asttoolkit-0.3.0}/astToolkit/__init__.py +0 -7
  4. {asttoolkit-0.2.3 → asttoolkit-0.3.0}/astToolkit/_astTypes.py +12 -36
  5. {asttoolkit-0.2.3 → asttoolkit-0.3.0}/astToolkit/_toolBe.py +36 -42
  6. {asttoolkit-0.2.3 → asttoolkit-0.3.0}/astToolkit/_toolClassIsAndAttribute.py +24 -36
  7. {asttoolkit-0.2.3 → asttoolkit-0.3.0}/astToolkit/_toolDOT.py +13 -22
  8. {asttoolkit-0.2.3 → asttoolkit-0.3.0}/astToolkit/_toolGrab.py +18 -30
  9. {asttoolkit-0.2.3 → asttoolkit-0.3.0}/astToolkit/_toolIfThis.py +27 -27
  10. asttoolkit-0.3.0/astToolkit/_toolMake.py +390 -0
  11. {asttoolkit-0.2.3 → asttoolkit-0.3.0}/astToolkit/_toolThen.py +3 -3
  12. {asttoolkit-0.2.3 → asttoolkit-0.3.0}/astToolkit/_toolkitAST.py +11 -10
  13. {asttoolkit-0.2.3 → asttoolkit-0.3.0}/astToolkit/_toolkitContainers.py +10 -10
  14. {asttoolkit-0.2.3 → asttoolkit-0.3.0}/astToolkit/_toolkitNodeVisitor.py +2 -2
  15. {asttoolkit-0.2.3 → asttoolkit-0.3.0}/astToolkit/_types.py +3 -19
  16. {asttoolkit-0.2.3 → asttoolkit-0.3.0}/astToolkit/transformationTools.py +41 -25
  17. {asttoolkit-0.2.3 → asttoolkit-0.3.0}/astToolkit.egg-info/PKG-INFO +22 -22
  18. {asttoolkit-0.2.3 → asttoolkit-0.3.0}/astToolkit.egg-info/SOURCES.txt +0 -4
  19. {asttoolkit-0.2.3 → asttoolkit-0.3.0}/pyproject.toml +2 -2
  20. {asttoolkit-0.2.3 → asttoolkit-0.3.0}/toolFactory/Z0Z_hardcoded.py +40 -17
  21. {asttoolkit-0.2.3 → asttoolkit-0.3.0}/toolFactory/__init__.py +6 -6
  22. {asttoolkit-0.2.3 → asttoolkit-0.3.0}/toolFactory/_snippets.py +4 -0
  23. asttoolkit-0.3.0/toolFactory/datacenter.py +263 -0
  24. {asttoolkit-0.2.3 → asttoolkit-0.3.0}/toolFactory/docstrings.py +7 -7
  25. {asttoolkit-0.2.3 → asttoolkit-0.3.0}/toolFactory/factory3.py +202 -95
  26. {asttoolkit-0.2.3 → asttoolkit-0.3.0}/toolFactory/factory_annex.py +0 -8
  27. asttoolkit-0.2.3/astToolkit/_toolMake.py +0 -339
  28. asttoolkit-0.2.3/astToolkit/_typesSpecial.py +0 -16
  29. asttoolkit-0.2.3/toolFactory/Z0Z_makeAstTools.py +0 -43
  30. asttoolkit-0.2.3/toolFactory/astFactory.py +0 -574
  31. asttoolkit-0.2.3/toolFactory/databaseASTCreation.py +0 -154
  32. asttoolkit-0.2.3/toolFactory/datacenter.py +0 -270
  33. {asttoolkit-0.2.3 → asttoolkit-0.3.0}/LICENSE +0 -0
  34. {asttoolkit-0.2.3 → asttoolkit-0.3.0}/astToolkit/py.typed +0 -0
  35. {asttoolkit-0.2.3 → asttoolkit-0.3.0}/astToolkit/theSSOT.py +0 -0
  36. {asttoolkit-0.2.3 → asttoolkit-0.3.0}/astToolkit.egg-info/dependency_links.txt +0 -0
  37. {asttoolkit-0.2.3 → asttoolkit-0.3.0}/astToolkit.egg-info/requires.txt +0 -0
  38. {asttoolkit-0.2.3 → asttoolkit-0.3.0}/astToolkit.egg-info/top_level.txt +0 -0
  39. {asttoolkit-0.2.3 → asttoolkit-0.3.0}/setup.cfg +0 -0
  40. {asttoolkit-0.2.3 → asttoolkit-0.3.0}/tests/test_basic.py +0 -0
  41. {asttoolkit-0.2.3 → asttoolkit-0.3.0}/toolFactory/py.typed +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: astToolkit
3
- Version: 0.2.3
3
+ Version: 0.3.0
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
@@ -25,7 +25,7 @@ Classifier: Typing :: Typed
25
25
  Classifier: Topic :: Software Development :: Code Generators
26
26
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
27
27
  Classifier: Topic :: Scientific/Engineering :: Information Analysis
28
- Requires-Python: >=3.10
28
+ Requires-Python: >=3.12
29
29
  Description-Content-Type: text/markdown
30
30
  License-File: LICENSE
31
31
  Requires-Dist: autoflake
@@ -183,32 +183,32 @@ print(ast.unparse(tree))
183
183
  This example shows a more complex transformation inspired by the mapFolding package:
184
184
 
185
185
  ```python
186
- from astToolkit import ast_Identifier, Be, DOT, Grab, IfThis as astToolkit_IfThis, Make, NodeChanger, Then
186
+ from astToolkit import str, Be, DOT, Grab, IfThis as astToolkit_IfThis, Make, NodeChanger, Then
187
187
  import ast
188
188
 
189
189
  # Define custom predicates by extending IfThis
190
190
  class IfThis(astToolkit_IfThis):
191
191
  @staticmethod
192
- def isAttributeNamespace_IdentifierGreaterThan0(
193
- namespace: ast_Identifier,
194
- identifier: ast_Identifier
192
+ def isAttributeNamespaceIdentifierGreaterThan0(
193
+ namespace: str,
194
+ identifier: str
195
195
  ) -> Callable[[ast.AST], TypeGuard[ast.Compare] | bool]:
196
196
 
197
197
  return lambda node: (
198
198
  Be.Compare(node)
199
- and IfThis.isAttributeNamespace_Identifier(namespace, identifier)(DOT.left(node))
199
+ and IfThis.isAttributeNamespaceIdentifier(namespace, identifier)(DOT.left(node))
200
200
  and Be.Gt(node.ops[0])
201
201
  and IfThis.isConstant_value(0)(node.comparators[0]))
202
202
 
203
203
  @staticmethod
204
- def isWhileAttributeNamespace_IdentifierGreaterThan0(
205
- namespace: ast_Identifier,
206
- identifier: ast_Identifier
204
+ def isWhileAttributeNamespaceIdentifierGreaterThan0(
205
+ namespace: str,
206
+ identifier: str
207
207
  ) -> Callable[[ast.AST], TypeGuard[ast.While] | bool]:
208
208
 
209
209
  return lambda node: (
210
210
  Be.While(node)
211
- and IfThis.isAttributeNamespace_IdentifierGreaterThan0(namespace, identifier)(DOT.test(node)))
211
+ and IfThis.isAttributeNamespaceIdentifierGreaterThan0(namespace, identifier)(DOT.test(node)))
212
212
 
213
213
  # Parse some code
214
214
  code = """
@@ -219,7 +219,7 @@ while claude.counter > 0:
219
219
  tree = ast.parse(code)
220
220
 
221
221
  # Find the while loop with our custom predicate
222
- find_while_loop = IfThis.isWhileAttributeNamespace_IdentifierGreaterThan0("claude", "counter")
222
+ find_while_loop = IfThis.isWhileAttributeNamespaceIdentifierGreaterThan0("claude", "counter")
223
223
 
224
224
  # Replace counter > 0 with counter > 1
225
225
  change_condition = Grab.testAttribute(
@@ -255,7 +255,7 @@ module_ast = parseLogicalPath2astModule("my_package.source_module")
255
255
  # Extract a function and track its imports
256
256
  function_name = "target_function"
257
257
  function_def = NodeTourist(
258
- IfThis.isFunctionDef_Identifier(function_name),
258
+ IfThis.isFunctionDefIdentifier(function_name),
259
259
  Then.extractIt
260
260
  ).captureLastMatch(module_ast)
261
261
 
@@ -290,34 +290,34 @@ if function_def:
290
290
  To create specialized patterns for your codebase, extend the core classes:
291
291
 
292
292
  ```python
293
- from astToolkit import ast_Identifier, Be, IfThis as astToolkit_IfThis
293
+ from astToolkit import str, Be, IfThis as astToolkit_IfThis
294
294
  from collections.abc import Callable
295
295
  from typing import TypeGuard
296
296
  import ast
297
297
 
298
298
  class IfThis(astToolkit_IfThis):
299
299
  @staticmethod
300
- def isAttributeNamespace_IdentifierGreaterThan0(
301
- namespace: ast_Identifier,
302
- identifier: ast_Identifier
300
+ def isAttributeNamespaceIdentifierGreaterThan0(
301
+ namespace: str,
302
+ identifier: str
303
303
  ) -> Callable[[ast.AST], TypeGuard[ast.Compare] | bool]:
304
304
  """Find comparisons like 'state.counter > 0'"""
305
305
  return lambda node: (
306
306
  Be.Compare(node)
307
- and IfThis.isAttributeNamespace_Identifier(namespace, identifier)(node.left)
307
+ and IfThis.isAttributeNamespaceIdentifier(namespace, identifier)(node.left)
308
308
  and Be.Gt(node.ops[0])
309
309
  and IfThis.isConstant_value(0)(node.comparators[0])
310
310
  )
311
311
 
312
312
  @staticmethod
313
- def isWhileAttributeNamespace_IdentifierGreaterThan0(
314
- namespace: ast_Identifier,
315
- identifier: ast_Identifier
313
+ def isWhileAttributeNamespaceIdentifierGreaterThan0(
314
+ namespace: str,
315
+ identifier: str
316
316
  ) -> Callable[[ast.AST], TypeGuard[ast.While] | bool]:
317
317
  """Find while loops like 'while state.counter > 0:'"""
318
318
  return lambda node: (
319
319
  Be.While(node)
320
- and IfThis.isAttributeNamespace_IdentifierGreaterThan0(namespace, identifier)(node.test)
320
+ and IfThis.isAttributeNamespaceIdentifierGreaterThan0(namespace, identifier)(node.test)
321
321
  )
322
322
  ```
323
323
 
@@ -140,32 +140,32 @@ print(ast.unparse(tree))
140
140
  This example shows a more complex transformation inspired by the mapFolding package:
141
141
 
142
142
  ```python
143
- from astToolkit import ast_Identifier, Be, DOT, Grab, IfThis as astToolkit_IfThis, Make, NodeChanger, Then
143
+ from astToolkit import str, Be, DOT, Grab, IfThis as astToolkit_IfThis, Make, NodeChanger, Then
144
144
  import ast
145
145
 
146
146
  # Define custom predicates by extending IfThis
147
147
  class IfThis(astToolkit_IfThis):
148
148
  @staticmethod
149
- def isAttributeNamespace_IdentifierGreaterThan0(
150
- namespace: ast_Identifier,
151
- identifier: ast_Identifier
149
+ def isAttributeNamespaceIdentifierGreaterThan0(
150
+ namespace: str,
151
+ identifier: str
152
152
  ) -> Callable[[ast.AST], TypeGuard[ast.Compare] | bool]:
153
153
 
154
154
  return lambda node: (
155
155
  Be.Compare(node)
156
- and IfThis.isAttributeNamespace_Identifier(namespace, identifier)(DOT.left(node))
156
+ and IfThis.isAttributeNamespaceIdentifier(namespace, identifier)(DOT.left(node))
157
157
  and Be.Gt(node.ops[0])
158
158
  and IfThis.isConstant_value(0)(node.comparators[0]))
159
159
 
160
160
  @staticmethod
161
- def isWhileAttributeNamespace_IdentifierGreaterThan0(
162
- namespace: ast_Identifier,
163
- identifier: ast_Identifier
161
+ def isWhileAttributeNamespaceIdentifierGreaterThan0(
162
+ namespace: str,
163
+ identifier: str
164
164
  ) -> Callable[[ast.AST], TypeGuard[ast.While] | bool]:
165
165
 
166
166
  return lambda node: (
167
167
  Be.While(node)
168
- and IfThis.isAttributeNamespace_IdentifierGreaterThan0(namespace, identifier)(DOT.test(node)))
168
+ and IfThis.isAttributeNamespaceIdentifierGreaterThan0(namespace, identifier)(DOT.test(node)))
169
169
 
170
170
  # Parse some code
171
171
  code = """
@@ -176,7 +176,7 @@ while claude.counter > 0:
176
176
  tree = ast.parse(code)
177
177
 
178
178
  # Find the while loop with our custom predicate
179
- find_while_loop = IfThis.isWhileAttributeNamespace_IdentifierGreaterThan0("claude", "counter")
179
+ find_while_loop = IfThis.isWhileAttributeNamespaceIdentifierGreaterThan0("claude", "counter")
180
180
 
181
181
  # Replace counter > 0 with counter > 1
182
182
  change_condition = Grab.testAttribute(
@@ -212,7 +212,7 @@ module_ast = parseLogicalPath2astModule("my_package.source_module")
212
212
  # Extract a function and track its imports
213
213
  function_name = "target_function"
214
214
  function_def = NodeTourist(
215
- IfThis.isFunctionDef_Identifier(function_name),
215
+ IfThis.isFunctionDefIdentifier(function_name),
216
216
  Then.extractIt
217
217
  ).captureLastMatch(module_ast)
218
218
 
@@ -247,34 +247,34 @@ if function_def:
247
247
  To create specialized patterns for your codebase, extend the core classes:
248
248
 
249
249
  ```python
250
- from astToolkit import ast_Identifier, Be, IfThis as astToolkit_IfThis
250
+ from astToolkit import str, Be, IfThis as astToolkit_IfThis
251
251
  from collections.abc import Callable
252
252
  from typing import TypeGuard
253
253
  import ast
254
254
 
255
255
  class IfThis(astToolkit_IfThis):
256
256
  @staticmethod
257
- def isAttributeNamespace_IdentifierGreaterThan0(
258
- namespace: ast_Identifier,
259
- identifier: ast_Identifier
257
+ def isAttributeNamespaceIdentifierGreaterThan0(
258
+ namespace: str,
259
+ identifier: str
260
260
  ) -> Callable[[ast.AST], TypeGuard[ast.Compare] | bool]:
261
261
  """Find comparisons like 'state.counter > 0'"""
262
262
  return lambda node: (
263
263
  Be.Compare(node)
264
- and IfThis.isAttributeNamespace_Identifier(namespace, identifier)(node.left)
264
+ and IfThis.isAttributeNamespaceIdentifier(namespace, identifier)(node.left)
265
265
  and Be.Gt(node.ops[0])
266
266
  and IfThis.isConstant_value(0)(node.comparators[0])
267
267
  )
268
268
 
269
269
  @staticmethod
270
- def isWhileAttributeNamespace_IdentifierGreaterThan0(
271
- namespace: ast_Identifier,
272
- identifier: ast_Identifier
270
+ def isWhileAttributeNamespaceIdentifierGreaterThan0(
271
+ namespace: str,
272
+ identifier: str
273
273
  ) -> Callable[[ast.AST], TypeGuard[ast.While] | bool]:
274
274
  """Find while loops like 'while state.counter > 0:'"""
275
275
  return lambda node: (
276
276
  Be.While(node)
277
- and IfThis.isAttributeNamespace_IdentifierGreaterThan0(namespace, identifier)(node.test)
277
+ and IfThis.isAttributeNamespaceIdentifierGreaterThan0(namespace, identifier)(node.test)
278
278
  )
279
279
  ```
280
280
 
@@ -1,15 +1,8 @@
1
- from astToolkit._typesSpecial import (
2
- NotRequired as NotRequired,
3
- TypedDict as TypedDict,
4
- )
5
-
6
1
  from astToolkit._astTypes import * # noqa: F403
7
2
 
8
3
  from astToolkit.theSSOT import FREAKOUT as FREAKOUT, The as The
9
4
 
10
5
  from astToolkit._types import (
11
- ast_expr_Slice as ast_expr_Slice,
12
- ast_Identifier as ast_Identifier,
13
6
  NodeORattribute as NodeORattribute,
14
7
  str_nameDOTname as str_nameDOTname,
15
8
  个 as 个,
@@ -20,13 +20,9 @@ hasDOTasname: typing_TypeAlias = ast.alias
20
20
  hasDOTattr: typing_TypeAlias = ast.Attribute
21
21
  hasDOTbases: typing_TypeAlias = ast.ClassDef
22
22
  hasDOTbody_expr: typing_TypeAlias = ast.Expression | ast.IfExp | ast.Lambda
23
- if sys.version_info >= (3, 11):
24
- hasDOTbody_list_stmt: typing_TypeAlias = ast.AsyncFor | ast.AsyncFunctionDef | ast.AsyncWith | ast.ClassDef | ast.ExceptHandler | ast.For | ast.FunctionDef | ast.If | ast.Interactive | ast.match_case | ast.Module | ast.Try | ast.TryStar | ast.While | ast.With
25
- else:
26
- hasDOTbody_list_stmt: typing_TypeAlias = ast.AsyncFor | ast.AsyncFunctionDef | ast.AsyncWith | ast.ClassDef | ast.ExceptHandler | ast.For | ast.FunctionDef | ast.If | ast.Interactive | ast.match_case | ast.Module | ast.Try | ast.While | ast.With
23
+ hasDOTbody_list_stmt: typing_TypeAlias = ast.AsyncFor | ast.AsyncFunctionDef | ast.AsyncWith | ast.ClassDef | ast.ExceptHandler | ast.For | ast.FunctionDef | ast.If | ast.Interactive | ast.match_case | ast.Module | ast.Try | ast.TryStar | ast.While | ast.With
27
24
  hasDOTbody: typing_TypeAlias = hasDOTbody_expr | hasDOTbody_list_stmt
28
- if sys.version_info >= (3, 12):
29
- hasDOTbound: typing_TypeAlias = ast.TypeVar
25
+ hasDOTbound: typing_TypeAlias = ast.TypeVar
30
26
  hasDOTcases: typing_TypeAlias = ast.Match
31
27
  hasDOTcause: typing_TypeAlias = ast.Raise
32
28
  hasDOTcls: typing_TypeAlias = ast.MatchClass
@@ -41,18 +37,12 @@ hasDOTdefaults: typing_TypeAlias = ast.arguments
41
37
  hasDOTelt: typing_TypeAlias = ast.GeneratorExp | ast.ListComp | ast.SetComp
42
38
  hasDOTelts: typing_TypeAlias = ast.List | ast.Set | ast.Tuple
43
39
  hasDOTexc: typing_TypeAlias = ast.Raise
44
- if sys.version_info >= (3, 11):
45
- hasDOTfinalbody: typing_TypeAlias = ast.Try | ast.TryStar
46
- else:
47
- hasDOTfinalbody: typing_TypeAlias = ast.Try
40
+ hasDOTfinalbody: typing_TypeAlias = ast.Try | ast.TryStar
48
41
  hasDOTformat_spec: typing_TypeAlias = ast.FormattedValue
49
42
  hasDOTfunc: typing_TypeAlias = ast.Call
50
43
  hasDOTgenerators: typing_TypeAlias = ast.DictComp | ast.GeneratorExp | ast.ListComp | ast.SetComp
51
44
  hasDOTguard: typing_TypeAlias = ast.match_case
52
- if sys.version_info >= (3, 11):
53
- hasDOThandlers: typing_TypeAlias = ast.Try | ast.TryStar
54
- else:
55
- hasDOThandlers: typing_TypeAlias = ast.Try
45
+ hasDOThandlers: typing_TypeAlias = ast.Try | ast.TryStar
56
46
  hasDOTid: typing_TypeAlias = ast.Name
57
47
  hasDOTifs: typing_TypeAlias = ast.comprehension
58
48
  hasDOTis_async: typing_TypeAlias = ast.comprehension
@@ -75,17 +65,10 @@ hasDOTlineno: typing_TypeAlias = ast.TypeIgnore
75
65
  hasDOTlower: typing_TypeAlias = ast.Slice
76
66
  hasDOTmodule: typing_TypeAlias = ast.ImportFrom
77
67
  hasDOTmsg: typing_TypeAlias = ast.Assert
78
- if sys.version_info >= (3, 12):
79
- hasDOTname_Name: typing_TypeAlias = ast.TypeAlias
80
- if sys.version_info >= (3, 12):
81
- hasDOTname_str: typing_TypeAlias = ast.alias | ast.AsyncFunctionDef | ast.ClassDef | ast.FunctionDef | ast.ParamSpec | ast.TypeVar | ast.TypeVarTuple
82
- else:
83
- hasDOTname_str: typing_TypeAlias = ast.alias | ast.AsyncFunctionDef | ast.ClassDef | ast.FunctionDef
68
+ hasDOTname_Name: typing_TypeAlias = ast.TypeAlias
69
+ hasDOTname_str: typing_TypeAlias = ast.alias | ast.AsyncFunctionDef | ast.ClassDef | ast.FunctionDef | ast.ParamSpec | ast.TypeVar | ast.TypeVarTuple
84
70
  hasDOTname_strOrNone: typing_TypeAlias = ast.ExceptHandler | ast.MatchAs | ast.MatchStar
85
- if sys.version_info >= (3, 12):
86
- hasDOTname: typing_TypeAlias = hasDOTname_Name | hasDOTname_str | hasDOTname_strOrNone
87
- else:
88
- hasDOTname: typing_TypeAlias = hasDOTname_str | hasDOTname_strOrNone
71
+ hasDOTname: typing_TypeAlias = hasDOTname_Name | hasDOTname_str | hasDOTname_strOrNone
89
72
  hasDOTnames_list_alias: typing_TypeAlias = ast.Import | ast.ImportFrom
90
73
  hasDOTnames_list_str: typing_TypeAlias = ast.Global | ast.Nonlocal
91
74
  hasDOTnames: typing_TypeAlias = hasDOTnames_list_alias | hasDOTnames_list_str
@@ -97,10 +80,7 @@ hasDOToperand: typing_TypeAlias = ast.UnaryOp
97
80
  hasDOTops: typing_TypeAlias = ast.Compare
98
81
  hasDOToptional_vars: typing_TypeAlias = ast.withitem
99
82
  hasDOTorelse_expr: typing_TypeAlias = ast.IfExp
100
- if sys.version_info >= (3, 11):
101
- hasDOTorelse_list_stmt: typing_TypeAlias = ast.AsyncFor | ast.For | ast.If | ast.Try | ast.TryStar | ast.While
102
- else:
103
- hasDOTorelse_list_stmt: typing_TypeAlias = ast.AsyncFor | ast.For | ast.If | ast.Try | ast.While
83
+ hasDOTorelse_list_stmt: typing_TypeAlias = ast.AsyncFor | ast.For | ast.If | ast.Try | ast.TryStar | ast.While
104
84
  hasDOTorelse: typing_TypeAlias = hasDOTorelse_expr | hasDOTorelse_list_stmt
105
85
  hasDOTpattern_pattern: typing_TypeAlias = ast.match_case
106
86
  hasDOTpattern_patternOrNone: typing_TypeAlias = ast.MatchAs
@@ -117,24 +97,20 @@ hasDOTslice: typing_TypeAlias = ast.Subscript
117
97
  hasDOTstep: typing_TypeAlias = ast.Slice
118
98
  hasDOTsubject: typing_TypeAlias = ast.Match
119
99
  hasDOTtag: typing_TypeAlias = ast.TypeIgnore
120
- hasDOTtarget_expr: typing_TypeAlias = ast.AsyncFor | ast.comprehension | ast.For
121
100
  hasDOTtarget_Name: typing_TypeAlias = ast.NamedExpr
122
101
  hasDOTtarget_NameOrAttributeOrSubscript: typing_TypeAlias = ast.AnnAssign | ast.AugAssign
123
- hasDOTtarget: typing_TypeAlias = hasDOTtarget_expr | hasDOTtarget_Name | hasDOTtarget_NameOrAttributeOrSubscript
102
+ hasDOTtarget_expr: typing_TypeAlias = ast.AsyncFor | ast.comprehension | ast.For
103
+ hasDOTtarget: typing_TypeAlias = hasDOTtarget_Name | hasDOTtarget_NameOrAttributeOrSubscript | hasDOTtarget_expr
124
104
  hasDOTtargets: typing_TypeAlias = ast.Assign | ast.Delete
125
105
  hasDOTtest: typing_TypeAlias = ast.Assert | ast.If | ast.IfExp | ast.While
126
106
  hasDOTtype: typing_TypeAlias = ast.ExceptHandler
127
107
  hasDOTtype_comment: typing_TypeAlias = ast.arg | ast.Assign | ast.AsyncFor | ast.AsyncFunctionDef | ast.AsyncWith | ast.For | ast.FunctionDef | ast.With
128
108
  hasDOTtype_ignores: typing_TypeAlias = ast.Module
129
- if sys.version_info >= (3, 12):
130
- hasDOTtype_params: typing_TypeAlias = ast.AsyncFunctionDef | ast.ClassDef | ast.FunctionDef | ast.TypeAlias
109
+ hasDOTtype_params: typing_TypeAlias = ast.AsyncFunctionDef | ast.ClassDef | ast.FunctionDef | ast.TypeAlias
131
110
  hasDOTupper: typing_TypeAlias = ast.Slice
132
111
  hasDOTvalue_Any: typing_TypeAlias = ast.Constant
133
112
  hasDOTvalue_boolOrNone: typing_TypeAlias = ast.MatchSingleton
134
- if sys.version_info >= (3, 12):
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
136
- else:
137
- 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.YieldFrom
113
+ 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
138
114
  hasDOTvalue_exprOrNone: typing_TypeAlias = ast.AnnAssign | ast.Return | ast.Yield
139
115
  hasDOTvalue: typing_TypeAlias = hasDOTvalue_Any | hasDOTvalue_boolOrNone | hasDOTvalue_expr | hasDOTvalue_exprOrNone
140
116
  hasDOTvalues: typing_TypeAlias = ast.BoolOp | ast.Dict | ast.JoinedStr
@@ -95,14 +95,14 @@ class Be:
95
95
  def BitXor(node: ast.AST) -> TypeGuard[ast.BitXor]:
96
96
  return isinstance(node, ast.BitXor)
97
97
 
98
- @staticmethod
99
- def BoolOp(node: ast.AST) -> TypeGuard[ast.BoolOp]:
100
- return isinstance(node, ast.BoolOp)
101
-
102
98
  @staticmethod
103
99
  def boolop(node: ast.AST) -> TypeGuard[ast.boolop]:
104
100
  return isinstance(node, ast.boolop)
105
101
 
102
+ @staticmethod
103
+ def BoolOp(node: ast.AST) -> TypeGuard[ast.BoolOp]:
104
+ return isinstance(node, ast.BoolOp)
105
+
106
106
  @staticmethod
107
107
  def Break(node: ast.AST) -> TypeGuard[ast.Break]:
108
108
  return isinstance(node, ast.Break)
@@ -159,22 +159,22 @@ class Be:
159
159
  def Eq(node: ast.AST) -> TypeGuard[ast.Eq]:
160
160
  return isinstance(node, ast.Eq)
161
161
 
162
- @staticmethod
163
- def ExceptHandler(node: ast.AST) -> TypeGuard[ast.ExceptHandler]:
164
- return isinstance(node, ast.ExceptHandler)
165
-
166
162
  @staticmethod
167
163
  def excepthandler(node: ast.AST) -> TypeGuard[ast.excepthandler]:
168
164
  return isinstance(node, ast.excepthandler)
169
165
 
170
166
  @staticmethod
171
- def Expr(node: ast.AST) -> TypeGuard[ast.Expr]:
172
- return isinstance(node, ast.Expr)
167
+ def ExceptHandler(node: ast.AST) -> TypeGuard[ast.ExceptHandler]:
168
+ return isinstance(node, ast.ExceptHandler)
173
169
 
174
170
  @staticmethod
175
171
  def expr(node: ast.AST) -> TypeGuard[ast.expr]:
176
172
  return isinstance(node, ast.expr)
177
173
 
174
+ @staticmethod
175
+ def Expr(node: ast.AST) -> TypeGuard[ast.Expr]:
176
+ return isinstance(node, ast.Expr)
177
+
178
178
  @staticmethod
179
179
  def expr_context(node: ast.AST) -> TypeGuard[ast.expr_context]:
180
180
  return isinstance(node, ast.expr_context)
@@ -335,14 +335,14 @@ class Be:
335
335
  def MatMult(node: ast.AST) -> TypeGuard[ast.MatMult]:
336
336
  return isinstance(node, ast.MatMult)
337
337
 
338
- @staticmethod
339
- def Mod(node: ast.AST) -> TypeGuard[ast.Mod]:
340
- return isinstance(node, ast.Mod)
341
-
342
338
  @staticmethod
343
339
  def mod(node: ast.AST) -> TypeGuard[ast.mod]:
344
340
  return isinstance(node, ast.mod)
345
341
 
342
+ @staticmethod
343
+ def Mod(node: ast.AST) -> TypeGuard[ast.Mod]:
344
+ return isinstance(node, ast.Mod)
345
+
346
346
  @staticmethod
347
347
  def Module(node: ast.AST) -> TypeGuard[ast.Module]:
348
348
  return isinstance(node, ast.Module)
@@ -382,11 +382,10 @@ class Be:
382
382
  @staticmethod
383
383
  def Or(node: ast.AST) -> TypeGuard[ast.Or]:
384
384
  return isinstance(node, ast.Or)
385
- if sys.version_info >= (3, 12):
386
385
 
387
- @staticmethod
388
- def ParamSpec(node: ast.AST) -> TypeGuard[ast.ParamSpec]:
389
- return isinstance(node, ast.ParamSpec)
386
+ @staticmethod
387
+ def ParamSpec(node: ast.AST) -> TypeGuard[ast.ParamSpec]:
388
+ return isinstance(node, ast.ParamSpec)
390
389
 
391
390
  @staticmethod
392
391
  def Pass(node: ast.AST) -> TypeGuard[ast.Pass]:
@@ -447,11 +446,10 @@ class Be:
447
446
  @staticmethod
448
447
  def Try(node: ast.AST) -> TypeGuard[ast.Try]:
449
448
  return isinstance(node, ast.Try)
450
- if sys.version_info >= (3, 11):
451
449
 
452
- @staticmethod
453
- def TryStar(node: ast.AST) -> TypeGuard[ast.TryStar]:
454
- return isinstance(node, ast.TryStar)
450
+ @staticmethod
451
+ def TryStar(node: ast.AST) -> TypeGuard[ast.TryStar]:
452
+ return isinstance(node, ast.TryStar)
455
453
 
456
454
  @staticmethod
457
455
  def Tuple(node: ast.AST) -> TypeGuard[ast.Tuple]:
@@ -460,43 +458,39 @@ class Be:
460
458
  @staticmethod
461
459
  def type_ignore(node: ast.AST) -> TypeGuard[ast.type_ignore]:
462
460
  return isinstance(node, ast.type_ignore)
463
- if sys.version_info >= (3, 12):
464
461
 
465
- @staticmethod
466
- def type_param(node: ast.AST) -> TypeGuard[ast.type_param]:
467
- return isinstance(node, ast.type_param)
468
- if sys.version_info >= (3, 12):
462
+ @staticmethod
463
+ def type_param(node: ast.AST) -> TypeGuard[ast.type_param]:
464
+ return isinstance(node, ast.type_param)
469
465
 
470
- @staticmethod
471
- def TypeAlias(node: ast.AST) -> TypeGuard[ast.TypeAlias]:
472
- return isinstance(node, ast.TypeAlias)
466
+ @staticmethod
467
+ def TypeAlias(node: ast.AST) -> TypeGuard[ast.TypeAlias]:
468
+ return isinstance(node, ast.TypeAlias)
473
469
 
474
470
  @staticmethod
475
471
  def TypeIgnore(node: ast.AST) -> TypeGuard[ast.TypeIgnore]:
476
472
  return isinstance(node, ast.TypeIgnore)
477
- if sys.version_info >= (3, 12):
478
473
 
479
- @staticmethod
480
- def TypeVar(node: ast.AST) -> TypeGuard[ast.TypeVar]:
481
- return isinstance(node, ast.TypeVar)
482
- if sys.version_info >= (3, 12):
474
+ @staticmethod
475
+ def TypeVar(node: ast.AST) -> TypeGuard[ast.TypeVar]:
476
+ return isinstance(node, ast.TypeVar)
483
477
 
484
- @staticmethod
485
- def TypeVarTuple(node: ast.AST) -> TypeGuard[ast.TypeVarTuple]:
486
- return isinstance(node, ast.TypeVarTuple)
478
+ @staticmethod
479
+ def TypeVarTuple(node: ast.AST) -> TypeGuard[ast.TypeVarTuple]:
480
+ return isinstance(node, ast.TypeVarTuple)
487
481
 
488
482
  @staticmethod
489
483
  def UAdd(node: ast.AST) -> TypeGuard[ast.UAdd]:
490
484
  return isinstance(node, ast.UAdd)
491
485
 
492
- @staticmethod
493
- def UnaryOp(node: ast.AST) -> TypeGuard[ast.UnaryOp]:
494
- return isinstance(node, ast.UnaryOp)
495
-
496
486
  @staticmethod
497
487
  def unaryop(node: ast.AST) -> TypeGuard[ast.unaryop]:
498
488
  return isinstance(node, ast.unaryop)
499
489
 
490
+ @staticmethod
491
+ def UnaryOp(node: ast.AST) -> TypeGuard[ast.UnaryOp]:
492
+ return isinstance(node, ast.UnaryOp)
493
+
500
494
  @staticmethod
501
495
  def USub(node: ast.AST) -> TypeGuard[ast.USub]:
502
496
  return isinstance(node, ast.USub)
@@ -9,15 +9,15 @@ import ast
9
9
  class ClassIsAndAttribute:
10
10
  """
11
11
  Create functions that verify AST nodes by type and attribute conditions.
12
-
13
- The ClassIsAndAttribute class provides static methods that generate conditional functions for determining if an AST
14
- node is of a specific type AND its attribute meets a specified condition. These functions return TypeGuard-enabled
12
+
13
+ The ClassIsAndAttribute class provides static methods that generate conditional functions for determining if an AST
14
+ node is of a specific type AND its attribute meets a specified condition. These functions return TypeGuard-enabled
15
15
  callables that can be used in conditional statements to narrow node types during code traversal and transformation.
16
-
16
+
17
17
  Each generated function performs two checks:
18
18
  1. Verifies that the node is of the specified AST type
19
19
  2. Tests if the specified attribute of the node meets a custom condition
20
-
20
+
21
21
  This enables complex filtering and targeting of AST nodes based on both their type and attribute contents.
22
22
  """
23
23
 
@@ -121,14 +121,13 @@ class ClassIsAndAttribute:
121
121
  def workhorse(node: ast.AST) -> TypeGuard[hasDOTbody] | bool:
122
122
  return isinstance(node, astClass) and attributeCondition(node.body)
123
123
  return workhorse
124
- if sys.version_info >= (3, 12):
125
124
 
126
- @staticmethod
127
- def boundIs(astClass: type[hasDOTbound], attributeCondition: Callable[[ast.expr | None], bool]) -> Callable[[ast.AST], TypeGuard[hasDOTbound] | bool]:
125
+ @staticmethod
126
+ def boundIs(astClass: type[hasDOTbound], attributeCondition: Callable[[ast.expr | None], bool]) -> Callable[[ast.AST], TypeGuard[hasDOTbound] | bool]:
128
127
 
129
- def workhorse(node: ast.AST) -> TypeGuard[hasDOTbound] | bool:
130
- return isinstance(node, astClass) and node.bound is not None and attributeCondition(node.bound)
131
- return workhorse
128
+ def workhorse(node: ast.AST) -> TypeGuard[hasDOTbound] | bool:
129
+ return isinstance(node, astClass) and node.bound is not None and attributeCondition(node.bound)
130
+ return workhorse
132
131
 
133
132
  @staticmethod
134
133
  def casesIs(astClass: type[hasDOTcases], attributeCondition: Callable[[list[ast.match_case]], bool]) -> Callable[[ast.AST], TypeGuard[hasDOTcases] | bool]:
@@ -413,12 +412,11 @@ class ClassIsAndAttribute:
413
412
  def workhorse(node: ast.AST) -> TypeGuard[hasDOTmsg] | bool:
414
413
  return isinstance(node, astClass) and node.msg is not None and attributeCondition(node.msg)
415
414
  return workhorse
416
- if sys.version_info >= (3, 12):
417
415
 
418
- @staticmethod
419
- @overload
420
- def nameIs(astClass: type[hasDOTname_Name], attributeCondition: Callable[[ast.Name], bool]) -> Callable[[ast.AST], TypeGuard[hasDOTname_Name] | bool]:
421
- ...
416
+ @staticmethod
417
+ @overload
418
+ def nameIs(astClass: type[hasDOTname_Name], attributeCondition: Callable[[ast.Name], bool]) -> Callable[[ast.AST], TypeGuard[hasDOTname_Name] | bool]:
419
+ ...
422
420
 
423
421
  @staticmethod
424
422
  @overload
@@ -429,22 +427,13 @@ class ClassIsAndAttribute:
429
427
  @overload
430
428
  def nameIs(astClass: type[hasDOTname_strOrNone], attributeCondition: Callable[[str | None], bool]) -> Callable[[ast.AST], TypeGuard[hasDOTname_strOrNone] | bool]:
431
429
  ...
432
- if sys.version_info >= (3, 12):
433
430
 
434
- @staticmethod
435
- def nameIs(astClass: type[hasDOTname], attributeCondition: Callable[[ast.Name], bool] | Callable[[str], bool] | Callable[[str | None], bool]) -> Callable[[ast.AST], TypeGuard[hasDOTname] | bool]:
436
-
437
- def workhorse(node: ast.AST) -> TypeGuard[hasDOTname] | bool:
438
- return isinstance(node, astClass) and node.name is not None and attributeCondition(node.name)
439
- return workhorse
440
- else:
441
-
442
- @staticmethod
443
- def nameIs(astClass: type[hasDOTname], attributeCondition: Callable[[str], bool] | Callable[[str | None], bool]) -> Callable[[ast.AST], TypeGuard[hasDOTname] | bool]:
431
+ @staticmethod
432
+ def nameIs(astClass: type[hasDOTname], attributeCondition: Callable[[ast.Name], bool] | Callable[[str], bool] | Callable[[str | None], bool]) -> Callable[[ast.AST], TypeGuard[hasDOTname] | bool]:
444
433
 
445
- def workhorse(node: ast.AST) -> TypeGuard[hasDOTname] | bool:
446
- return isinstance(node, astClass) and node.name is not None and attributeCondition(node.name)
447
- return workhorse
434
+ def workhorse(node: ast.AST) -> TypeGuard[hasDOTname] | bool:
435
+ return isinstance(node, astClass) and node.name is not None and attributeCondition(node.name)
436
+ return workhorse
448
437
 
449
438
  @staticmethod
450
439
  @overload
@@ -676,14 +665,13 @@ class ClassIsAndAttribute:
676
665
  def workhorse(node: ast.AST) -> TypeGuard[hasDOTtype_ignores] | bool:
677
666
  return isinstance(node, astClass) and attributeCondition(node.type_ignores)
678
667
  return workhorse
679
- if sys.version_info >= (3, 12):
680
668
 
681
- @staticmethod
682
- def type_paramsIs(astClass: type[hasDOTtype_params], attributeCondition: Callable[[list[ast.type_param]], bool]) -> Callable[[ast.AST], TypeGuard[hasDOTtype_params] | bool]:
669
+ @staticmethod
670
+ def type_paramsIs(astClass: type[hasDOTtype_params], attributeCondition: Callable[[list[ast.type_param]], bool]) -> Callable[[ast.AST], TypeGuard[hasDOTtype_params] | bool]:
683
671
 
684
- def workhorse(node: ast.AST) -> TypeGuard[hasDOTtype_params] | bool:
685
- return isinstance(node, astClass) and attributeCondition(node.type_params)
686
- return workhorse
672
+ def workhorse(node: ast.AST) -> TypeGuard[hasDOTtype_params] | bool:
673
+ return isinstance(node, astClass) and attributeCondition(node.type_params)
674
+ return workhorse
687
675
 
688
676
  @staticmethod
689
677
  def upperIs(astClass: type[hasDOTupper], attributeCondition: Callable[[ast.expr | None], bool]) -> Callable[[ast.AST], TypeGuard[hasDOTupper] | bool]: