astToolkit 0.6.0__tar.gz → 0.7.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.6.0 → asttoolkit-0.7.0}/PKG-INFO +6 -6
  2. {asttoolkit-0.6.0 → asttoolkit-0.7.0}/astToolkit/__init__.py +3 -2
  3. {asttoolkit-0.6.0 → asttoolkit-0.7.0}/astToolkit/_astTypes.py +1 -0
  4. asttoolkit-0.7.0/astToolkit/_dumpHandmade.py +100 -0
  5. asttoolkit-0.7.0/astToolkit/_prototypeFind.py +1283 -0
  6. asttoolkit-0.7.0/astToolkit/_theSSOT.py +4 -0
  7. {asttoolkit-0.6.0 → asttoolkit-0.7.0}/astToolkit/_toolBe.py +14 -14
  8. {asttoolkit-0.6.0 → asttoolkit-0.7.0}/astToolkit/_toolIfThis.py +12 -0
  9. {asttoolkit-0.6.0 → asttoolkit-0.7.0}/astToolkit/_toolMake.py +47 -6
  10. {asttoolkit-0.6.0 → asttoolkit-0.7.0}/astToolkit/_toolThen.py +4 -7
  11. {asttoolkit-0.6.0 → asttoolkit-0.7.0}/astToolkit/_toolkitNodeVisitor.py +3 -3
  12. {asttoolkit-0.6.0 → asttoolkit-0.7.0}/astToolkit.egg-info/PKG-INFO +6 -6
  13. {asttoolkit-0.6.0 → asttoolkit-0.7.0}/astToolkit.egg-info/SOURCES.txt +0 -2
  14. {asttoolkit-0.6.0 → asttoolkit-0.7.0}/astToolkit.egg-info/requires.txt +5 -5
  15. {asttoolkit-0.6.0 → asttoolkit-0.7.0}/pyproject.toml +6 -6
  16. {asttoolkit-0.6.0 → asttoolkit-0.7.0}/tests/dataSamples/Make.py +4 -4
  17. {asttoolkit-0.6.0 → asttoolkit-0.7.0}/tests/test_joinClassmethod.py +4 -4
  18. asttoolkit-0.6.0/astToolkit/_dumpHandmade.py +0 -97
  19. asttoolkit-0.6.0/astToolkit/_prototypeFind.py +0 -1902
  20. asttoolkit-0.6.0/astToolkit/_theSSOT.py +0 -22
  21. asttoolkit-0.6.0/tests/sampleData.py +0 -40
  22. asttoolkit-0.6.0/tests/test_basic.py +0 -193
  23. {asttoolkit-0.6.0 → asttoolkit-0.7.0}/LICENSE +0 -0
  24. {asttoolkit-0.6.0 → asttoolkit-0.7.0}/README.md +0 -0
  25. {asttoolkit-0.6.0 → asttoolkit-0.7.0}/astToolkit/_dumpFunctionDef.py +0 -0
  26. {asttoolkit-0.6.0 → asttoolkit-0.7.0}/astToolkit/_toolDOT.py +0 -0
  27. {asttoolkit-0.6.0 → asttoolkit-0.7.0}/astToolkit/_toolGrab.py +0 -0
  28. {asttoolkit-0.6.0 → asttoolkit-0.7.0}/astToolkit/_toolkitAST.py +0 -0
  29. {asttoolkit-0.6.0 → asttoolkit-0.7.0}/astToolkit/_toolkitContainers.py +0 -0
  30. {asttoolkit-0.6.0 → asttoolkit-0.7.0}/astToolkit/py.typed +0 -0
  31. {asttoolkit-0.6.0 → asttoolkit-0.7.0}/astToolkit/transformationTools.py +0 -0
  32. {asttoolkit-0.6.0 → asttoolkit-0.7.0}/astToolkit.egg-info/dependency_links.txt +0 -0
  33. {asttoolkit-0.6.0 → asttoolkit-0.7.0}/astToolkit.egg-info/top_level.txt +0 -0
  34. {asttoolkit-0.6.0 → asttoolkit-0.7.0}/setup.cfg +0 -0
  35. {asttoolkit-0.6.0 → asttoolkit-0.7.0}/tests/__init__.py +0 -0
  36. {asttoolkit-0.6.0 → asttoolkit-0.7.0}/tests/conftest.py +0 -0
  37. {asttoolkit-0.6.0 → asttoolkit-0.7.0}/tests/dataSamples/__init__.py +0 -0
  38. {asttoolkit-0.6.0 → asttoolkit-0.7.0}/tests/dataSamples/createTestData.py +0 -0
  39. {asttoolkit-0.6.0 → asttoolkit-0.7.0}/tests/test_Be.py +0 -0
  40. {asttoolkit-0.6.0 → asttoolkit-0.7.0}/tests/test_Find.py +0 -0
  41. {asttoolkit-0.6.0 → asttoolkit-0.7.0}/tests/test_nodeVisitors.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: astToolkit
3
- Version: 0.6.0
3
+ Version: 0.7.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
@@ -19,6 +19,7 @@ Classifier: Programming Language :: Python
19
19
  Classifier: Programming Language :: Python :: 3
20
20
  Classifier: Programming Language :: Python :: 3.12
21
21
  Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Programming Language :: Python :: 3.14
22
23
  Classifier: Topic :: Scientific/Engineering :: Information Analysis
23
24
  Classifier: Topic :: Software Development :: Code Generators
24
25
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
@@ -29,15 +30,14 @@ License-File: LICENSE
29
30
  Requires-Dist: autoflake
30
31
  Requires-Dist: hunterMakesPy
31
32
  Requires-Dist: typing_extensions>=4.10.0
33
+ Provides-Extra: development
34
+ Requires-Dist: mypy; extra == "development"
35
+ Requires-Dist: pyupgrade; extra == "development"
36
+ Requires-Dist: setuptools-scm; extra == "development"
32
37
  Provides-Extra: testing
33
- Requires-Dist: mypy; extra == "testing"
34
38
  Requires-Dist: pytest-cov; extra == "testing"
35
39
  Requires-Dist: pytest-xdist; extra == "testing"
36
40
  Requires-Dist: pytest; extra == "testing"
37
- Requires-Dist: pyupgrade; extra == "testing"
38
- Requires-Dist: setuptools-scm; extra == "testing"
39
- Requires-Dist: tomli; extra == "testing"
40
- Requires-Dist: trove_classifiers; extra == "testing"
41
41
  Dynamic: license-file
42
42
 
43
43
  # astToolkit
@@ -64,7 +64,7 @@ import sys
64
64
 
65
65
  from astToolkit._astTypes import (
66
66
  ast_attributes as ast_attributes, ast_attributes_int as ast_attributes_int,
67
- ast_attributes_type_comment as ast_attributes_type_comment, ConstantValueType as ConstantValueType,
67
+ ast_attributes_type_comment as ast_attributes_type_comment, astASTattributes as astASTattributes, ConstantValueType as ConstantValueType,
68
68
  hasDOTannotation as hasDOTannotation, hasDOTannotation_expr as hasDOTannotation_expr,
69
69
  hasDOTannotation_exprOrNone as hasDOTannotation_exprOrNone, hasDOTarg as hasDOTarg, hasDOTarg_str as hasDOTarg_str,
70
70
  hasDOTarg_strOrNone as hasDOTarg_strOrNone, hasDOTargs as hasDOTargs, hasDOTargs_arguments as hasDOTargs_arguments,
@@ -110,7 +110,8 @@ from astToolkit._astTypes import (
110
110
  if sys.version_info >= (3, 13):
111
111
  from astToolkit._astTypes import hasDOTdefault_value as hasDOTdefault_value
112
112
 
113
- from astToolkit._dumpHandmade import dump as dump
113
+ if sys.version_info >= (3, 13):
114
+ from astToolkit._dumpHandmade import dump as dump
114
115
 
115
116
  from astToolkit._toolkitNodeVisitor import (
116
117
  NodeChanger as NodeChanger,
@@ -5,6 +5,7 @@ import ast
5
5
  import sys
6
6
 
7
7
  type ConstantValueType = bool | bytes | complex | EllipsisType | float | int | None | range | str
8
+ type astASTattributes = ast.AST | ConstantValueType | list[ast.AST] | list[ast.AST | None] | list[str]
8
9
  type identifierDotAttribute = str
9
10
  个 = typing_TypeVar('个', covariant=True)
10
11
  归个 = typing_TypeVar('归个', covariant=True)
@@ -0,0 +1,100 @@
1
+ from astToolkit import astASTattributes
2
+ import ast
3
+ import sys
4
+
5
+ if sys.version_info >= (3, 13):
6
+
7
+ def dump(node: ast.AST, *, annotate_fields: bool = True, include_attributes: bool = False, indent: int | str | None = None, show_empty: bool = False) -> str: # noqa: C901, PLR0915
8
+ """Return a formatted string representation of an `ast.AST` node.
9
+
10
+ Parameters
11
+ ----------
12
+ node : ast.AST
13
+ The `ast.AST` node to format.
14
+ annotate_fields : bool = True
15
+ Whether to include field names in the output.
16
+ include_attributes : bool = False
17
+ Whether to include node "_attributes" in addition to fields. The attributes in category `_attributes` are `lineno` (line
18
+ _**n**umer**o**_ (_Latin_ "number")), `col_offset` (***col***umn offset), `end_lineno` (end line _**n**umer**o**_ (_Latin_
19
+ "number")), and `end_col_offset` (end ***col***umn offset).
20
+ indent : int | str | None = None
21
+ String for indentation or number of spaces; `None` for single-line output.
22
+ show_empty : bool = False
23
+ Whether to include fields with empty list or `None` values.
24
+
25
+ Returns
26
+ -------
27
+ formattedString : str
28
+ String representation of the `ast.AST` node with specified formatting.
29
+
30
+ """
31
+ def _format(node: astASTattributes, level: int = 0) -> tuple[str, bool]: # noqa: C901, PLR0912, PLR0915
32
+ if indentString is not None:
33
+ level += 1
34
+ ImaIndent: str = '\n' + indentString * level
35
+ separator: str = ',\n' + indentString * level
36
+ else:
37
+ ImaIndent = ''
38
+ separator = ', '
39
+ if isinstance(node, ast.AST):
40
+ astAST: type[ast.AST] = type(node)
41
+ listAttributes: list[str] = []
42
+ attributeStaging: list[str] = []
43
+ simpleOutput: bool = True
44
+ showAnnotations: bool = annotate_fields
45
+ for name in node._fields:
46
+ try:
47
+ value: astASTattributes = getattr(node, name)
48
+ except AttributeError:
49
+ showAnnotations = True
50
+ continue
51
+ if value is None and getattr(astAST, name, ...) is None:
52
+ if show_empty:
53
+ listAttributes.append(f'{name}={value}')
54
+ showAnnotations = True
55
+ continue
56
+ if not show_empty:
57
+ if value == []:
58
+ field_type: astASTattributes = astAST._field_types.get(name, object) # noqa: SLF001
59
+ if getattr(field_type, '__origin__', ...) is list:
60
+ if not showAnnotations:
61
+ attributeStaging.append(repr(value))
62
+ continue
63
+ if not showAnnotations:
64
+ listAttributes.extend(attributeStaging)
65
+ attributeStaging = []
66
+ valueFormatted, simpleFormat = _format(value, level)
67
+ simpleOutput = simpleOutput and simpleFormat
68
+ if showAnnotations:
69
+ listAttributes.append(f'{name}={valueFormatted}')
70
+ else:
71
+ listAttributes.append(valueFormatted)
72
+ if include_attributes and node._attributes: # noqa: SLF001
73
+ for name_attributes in node._attributes: # noqa: SLF001
74
+ try:
75
+ value_attributes = getattr(node, name_attributes)
76
+ except AttributeError:
77
+ continue
78
+ if value_attributes is None and getattr(astAST, name_attributes, ...) is None:
79
+ continue
80
+ value_attributesFormatted, simpleFormat = _format(value_attributes, level)
81
+ simpleOutput = simpleOutput and simpleFormat
82
+ listAttributes.append(f'{name_attributes}={value_attributesFormatted}')
83
+ if simpleOutput and len(listAttributes) <= 3:
84
+ return (f"ast.{node.__class__.__name__}({', '.join(listAttributes)})", not bool(listAttributes))
85
+ return (f"ast.{node.__class__.__name__}({ImaIndent}{separator.join(listAttributes)})", False)
86
+ elif isinstance(node, list):
87
+ if not node:
88
+ return ('[]', True)
89
+ return (f'[{ImaIndent}{separator.join(_format(x, level)[0] for x in node)}]', False)
90
+ return (repr(node), True)
91
+
92
+ if not isinstance(node, ast.AST):
93
+ message = f'expected `ast.AST`, got {node.__class__.__name__!r}'
94
+ raise TypeError(message)
95
+ if indent is not None and not isinstance(indent, str):
96
+ indentString = " " * indent
97
+ else:
98
+ indentString = indent
99
+ return _format(node)[0]
100
+