astToolkit 0.3.4__tar.gz → 0.3.6__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.6}/PKG-INFO +5 -7
- {asttoolkit-0.3.4 → asttoolkit-0.3.6}/astToolkit/__init__.py +2 -1
- {asttoolkit-0.3.4 → asttoolkit-0.3.6}/astToolkit/_astTypes.py +16 -4
- asttoolkit-0.3.6/astToolkit/_dumpHandmade.py +91 -0
- asttoolkit-0.3.6/astToolkit/_dumpHandmade.pyi +43 -0
- asttoolkit-0.3.6/astToolkit/_joinClassmethod.py +586 -0
- {asttoolkit-0.3.4 → asttoolkit-0.3.6}/astToolkit/_theSSOT.py +4 -4
- {asttoolkit-0.3.4 → asttoolkit-0.3.6}/astToolkit/_toolBe.py +11 -11
- {asttoolkit-0.3.4 → asttoolkit-0.3.6}/astToolkit/_toolClassIsAndAttribute.py +13 -13
- {asttoolkit-0.3.4 → asttoolkit-0.3.6}/astToolkit/_toolDOT.py +36 -37
- {asttoolkit-0.3.4 → asttoolkit-0.3.6}/astToolkit/_toolGrab.py +23 -24
- {asttoolkit-0.3.4 → asttoolkit-0.3.6}/astToolkit/_toolMake.py +134 -119
- {asttoolkit-0.3.4 → asttoolkit-0.3.6}/astToolkit.egg-info/PKG-INFO +5 -7
- {asttoolkit-0.3.4 → asttoolkit-0.3.6}/astToolkit.egg-info/SOURCES.txt +2 -0
- asttoolkit-0.3.6/pyproject.toml +87 -0
- asttoolkit-0.3.4/astToolkit/_joinClassmethod.py +0 -1260
- asttoolkit-0.3.4/pyproject.toml +0 -65
- {asttoolkit-0.3.4 → asttoolkit-0.3.6}/LICENSE +0 -0
- {asttoolkit-0.3.4 → asttoolkit-0.3.6}/README.md +0 -0
- {asttoolkit-0.3.4 → asttoolkit-0.3.6}/astToolkit/_dumpFunctionDef.py +0 -0
- {asttoolkit-0.3.4 → asttoolkit-0.3.6}/astToolkit/_toolIfThis.py +0 -0
- {asttoolkit-0.3.4 → asttoolkit-0.3.6}/astToolkit/_toolThen.py +0 -0
- {asttoolkit-0.3.4 → asttoolkit-0.3.6}/astToolkit/_toolkitAST.py +0 -0
- {asttoolkit-0.3.4 → asttoolkit-0.3.6}/astToolkit/_toolkitContainers.py +0 -0
- {asttoolkit-0.3.4 → asttoolkit-0.3.6}/astToolkit/_toolkitNodeVisitor.py +0 -0
- {asttoolkit-0.3.4 → asttoolkit-0.3.6}/astToolkit/_types.py +0 -0
- {asttoolkit-0.3.4 → asttoolkit-0.3.6}/astToolkit/py.typed +0 -0
- {asttoolkit-0.3.4 → asttoolkit-0.3.6}/astToolkit/transformationTools.py +0 -0
- {asttoolkit-0.3.4 → asttoolkit-0.3.6}/astToolkit.egg-info/dependency_links.txt +0 -0
- {asttoolkit-0.3.4 → asttoolkit-0.3.6}/astToolkit.egg-info/requires.txt +1 -1
- {asttoolkit-0.3.4 → asttoolkit-0.3.6}/astToolkit.egg-info/top_level.txt +0 -0
- {asttoolkit-0.3.4 → asttoolkit-0.3.6}/setup.cfg +0 -0
- {asttoolkit-0.3.4 → asttoolkit-0.3.6}/tests/conftest.py +0 -0
- {asttoolkit-0.3.4 → asttoolkit-0.3.6}/tests/test_basic.py +0 -0
- {asttoolkit-0.3.4 → asttoolkit-0.3.6}/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.6
|
|
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
|
|
@@ -8,7 +8,7 @@ Project-URL: Donate, https://www.patreon.com/integrated
|
|
|
8
8
|
Project-URL: Homepage, https://github.com/hunterhogan/astToolkit
|
|
9
9
|
Project-URL: Issues, https://github.com/hunterhogan/astToolkit/issues
|
|
10
10
|
Project-URL: Repository, https://github.com/hunterhogan/astToolkit.git
|
|
11
|
-
Keywords:
|
|
11
|
+
Keywords: abstract syntax tree,ast,ast-analysis,ast-manipulation,ast-predicate,ast-traversal,ast-visitor,code generation,code transformation,code-analysis,code-refactoring,composable-apis,function-inlining,metaprogramming,python-ast,source-code-generation,static-analysis,type-safe,typed-ast,visitor-pattern
|
|
12
12
|
Classifier: Development Status :: 4 - Beta
|
|
13
13
|
Classifier: Environment :: Console
|
|
14
14
|
Classifier: Intended Audience :: Developers
|
|
@@ -17,21 +17,19 @@ 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
|
-
Classifier:
|
|
22
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
25
23
|
Classifier: Topic :: Software Development :: Code Generators
|
|
26
24
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
27
|
-
Classifier:
|
|
25
|
+
Classifier: Typing :: Typed
|
|
28
26
|
Requires-Python: >=3.12
|
|
29
27
|
Description-Content-Type: text/markdown
|
|
30
28
|
License-File: LICENSE
|
|
29
|
+
Requires-Dist: Z0Z_tools
|
|
31
30
|
Requires-Dist: autoflake
|
|
32
31
|
Requires-Dist: python_minifier
|
|
33
32
|
Requires-Dist: tomli
|
|
34
|
-
Requires-Dist: Z0Z_tools
|
|
35
33
|
Provides-Extra: testing
|
|
36
34
|
Requires-Dist: mypy; extra == "testing"
|
|
37
35
|
Requires-Dist: pytest; extra == "testing"
|
|
@@ -28,7 +28,8 @@ from astToolkit._types import (
|
|
|
28
28
|
str_nameDOTname as str_nameDOTname,
|
|
29
29
|
)
|
|
30
30
|
|
|
31
|
-
from astToolkit._dumpFunctionDef import dump as dump
|
|
31
|
+
# from astToolkit._dumpFunctionDef import dump as dump
|
|
32
|
+
from astToolkit._dumpHandmade import dump as dump
|
|
32
33
|
|
|
33
34
|
from astToolkit._toolkitNodeVisitor import (
|
|
34
35
|
NodeChanger as NodeChanger,
|
|
@@ -1,19 +1,31 @@
|
|
|
1
1
|
"""This file is generated automatically, so changes to this file will be lost."""
|
|
2
|
-
from
|
|
2
|
+
from types import EllipsisType, NotImplementedType
|
|
3
|
+
from typing import Any, TypeAlias as typing_TypeAlias, TypeVar as typing_TypeVar, TypedDict
|
|
3
4
|
import ast
|
|
4
5
|
import sys
|
|
5
6
|
intORstr: typing_TypeAlias = Any
|
|
6
7
|
intORstrORtype_params: typing_TypeAlias = Any
|
|
7
8
|
intORtype_params: typing_TypeAlias = Any
|
|
9
|
+
_Scalar: typing_TypeAlias = bool | bytes | complex | EllipsisType | float | int | None | NotImplementedType | range | str
|
|
10
|
+
ScalarOrContainerOfScalar: typing_TypeAlias = _Scalar | frozenset['ScalarOrContainerOfScalar'] | tuple['ScalarOrContainerOfScalar', ...]
|
|
8
11
|
木 = typing_TypeVar('木', bound=ast.AST, covariant=True)
|
|
9
12
|
个 = typing_TypeVar('个', covariant=True)
|
|
10
13
|
个return = typing_TypeVar('个return', covariant=True)
|
|
11
14
|
|
|
12
|
-
class
|
|
15
|
+
class _attributes(TypedDict, total=False):
|
|
13
16
|
lineno: int
|
|
14
17
|
col_offset: int
|
|
18
|
+
|
|
19
|
+
class ast_attributes(_attributes, total=False):
|
|
15
20
|
end_lineno: int | None
|
|
16
21
|
end_col_offset: int | None
|
|
22
|
+
|
|
23
|
+
class ast_attributes_int(_attributes, total=False):
|
|
24
|
+
end_lineno: int
|
|
25
|
+
end_col_offset: int
|
|
26
|
+
|
|
27
|
+
class ast_attributes_type_comment(ast_attributes, total=False):
|
|
28
|
+
type_comment: str | None
|
|
17
29
|
hasDOTannotation_expr: typing_TypeAlias = ast.AnnAssign
|
|
18
30
|
hasDOTannotation_exprOrNone: typing_TypeAlias = ast.arg
|
|
19
31
|
hasDOTannotation: typing_TypeAlias = hasDOTannotation_expr | hasDOTannotation_exprOrNone
|
|
@@ -117,10 +129,10 @@ hasDOTtype_comment: typing_TypeAlias = ast.arg | ast.Assign | ast.AsyncFor | ast
|
|
|
117
129
|
hasDOTtype_ignores: typing_TypeAlias = ast.Module
|
|
118
130
|
hasDOTtype_params: typing_TypeAlias = ast.AsyncFunctionDef | ast.ClassDef | ast.FunctionDef | ast.TypeAlias
|
|
119
131
|
hasDOTupper: typing_TypeAlias = ast.Slice
|
|
120
|
-
|
|
132
|
+
hasDOTvalue_ScalarOrContainerOfScalar: typing_TypeAlias = ast.Constant
|
|
121
133
|
hasDOTvalue_boolOrNone: typing_TypeAlias = ast.MatchSingleton
|
|
122
134
|
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
135
|
hasDOTvalue_exprOrNone: typing_TypeAlias = ast.AnnAssign | ast.Return | ast.Yield
|
|
124
|
-
hasDOTvalue: typing_TypeAlias =
|
|
136
|
+
hasDOTvalue: typing_TypeAlias = hasDOTvalue_ScalarOrContainerOfScalar | hasDOTvalue_boolOrNone | hasDOTvalue_expr | hasDOTvalue_exprOrNone
|
|
125
137
|
hasDOTvalues: typing_TypeAlias = ast.BoolOp | ast.Dict | ast.JoinedStr
|
|
126
138
|
hasDOTvararg: typing_TypeAlias = ast.arguments
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
from ast import AST, Constant, MatchSingleton
|
|
2
|
+
|
|
3
|
+
def dump(
|
|
4
|
+
node, annotate_fields=True, include_attributes=False,
|
|
5
|
+
*,
|
|
6
|
+
indent=None, show_empty=False,
|
|
7
|
+
):
|
|
8
|
+
"""
|
|
9
|
+
Return a formatted dump of the tree in node. This is mainly useful for
|
|
10
|
+
debugging purposes. If annotate_fields is true (by default),
|
|
11
|
+
the returned string will show the names and the values for fields.
|
|
12
|
+
If annotate_fields is false, the result string will be more compact by
|
|
13
|
+
omitting unambiguous field names. Attributes such as line
|
|
14
|
+
numbers and column offsets are not dumped by default. If this is wanted,
|
|
15
|
+
include_attributes can be set to true. If indent is a non-negative
|
|
16
|
+
integer or string, then the tree will be pretty-printed with that indent
|
|
17
|
+
level. None (the default) selects the single line representation.
|
|
18
|
+
If show_empty is False, then empty lists and fields that are None
|
|
19
|
+
will be omitted from the output for better readability.
|
|
20
|
+
"""
|
|
21
|
+
def _format(node, level=0):
|
|
22
|
+
if indent_str is not None:
|
|
23
|
+
level += 1
|
|
24
|
+
prefix = '\n' + indent_str * level
|
|
25
|
+
sep = ',\n' + indent_str * level
|
|
26
|
+
else:
|
|
27
|
+
prefix = ''
|
|
28
|
+
sep = ', '
|
|
29
|
+
if isinstance(node, AST):
|
|
30
|
+
cls = type(node)
|
|
31
|
+
args = []
|
|
32
|
+
args_buffer = []
|
|
33
|
+
allsimple = True
|
|
34
|
+
keywords = annotate_fields
|
|
35
|
+
for name in node._fields:
|
|
36
|
+
try:
|
|
37
|
+
value = getattr(node, name)
|
|
38
|
+
except AttributeError:
|
|
39
|
+
keywords = True
|
|
40
|
+
continue
|
|
41
|
+
if value is None and getattr(cls, name, ...) is None:
|
|
42
|
+
if show_empty:
|
|
43
|
+
args.append('%s=%s' % (name, value))
|
|
44
|
+
keywords = True
|
|
45
|
+
continue
|
|
46
|
+
elif (
|
|
47
|
+
not show_empty
|
|
48
|
+
and (value is None or value == [])
|
|
49
|
+
# Special cases:
|
|
50
|
+
# `Constant(value=None)` and `MatchSingleton(value=None)`
|
|
51
|
+
and not isinstance(node, (Constant, MatchSingleton))
|
|
52
|
+
):
|
|
53
|
+
args_buffer.append(repr(value))
|
|
54
|
+
continue
|
|
55
|
+
elif not keywords:
|
|
56
|
+
args.extend(args_buffer)
|
|
57
|
+
args_buffer = []
|
|
58
|
+
value_formatted, simple = _format(value, level)
|
|
59
|
+
allsimple = allsimple and simple
|
|
60
|
+
if keywords:
|
|
61
|
+
args.append('%s=%s' % (name, value_formatted))
|
|
62
|
+
else:
|
|
63
|
+
args.append(value_formatted)
|
|
64
|
+
if include_attributes and node._attributes:
|
|
65
|
+
for name_attributes in node._attributes:
|
|
66
|
+
try:
|
|
67
|
+
value_attributes = getattr(node, name_attributes)
|
|
68
|
+
except AttributeError:
|
|
69
|
+
continue
|
|
70
|
+
if value_attributes is None and getattr(cls, name_attributes, ...) is None:
|
|
71
|
+
continue
|
|
72
|
+
value_attributes_formatted, simple = _format(value_attributes, level)
|
|
73
|
+
allsimple = allsimple and simple
|
|
74
|
+
args.append('%s=%s' % (name_attributes, value_attributes_formatted))
|
|
75
|
+
if allsimple and len(args) <= 3:
|
|
76
|
+
return ('%s(%s)' % (f"{node.__class__.__module__}.{node.__class__.__name__}", ', '.join(args)), not args)
|
|
77
|
+
return ('%s(%s%s)' % (f"{node.__class__.__module__}.{node.__class__.__name__}", prefix, sep.join(args)), False)
|
|
78
|
+
elif isinstance(node, list):
|
|
79
|
+
if not node:
|
|
80
|
+
return ('[]', True)
|
|
81
|
+
return '[%s%s]' % (prefix, sep.join(_format(x, level)[0] for x in node)), False
|
|
82
|
+
return (repr(node), True)
|
|
83
|
+
|
|
84
|
+
if not isinstance(node, AST):
|
|
85
|
+
raise TypeError('expected AST, got %r' % node.__class__.__name__)
|
|
86
|
+
if indent is not None and not isinstance(indent, str):
|
|
87
|
+
indent_str = ' ' * indent
|
|
88
|
+
else:
|
|
89
|
+
indent_str = indent
|
|
90
|
+
return _format(node)[0]
|
|
91
|
+
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
from ast import AST
|
|
2
|
+
from types import EllipsisType, NotImplementedType
|
|
3
|
+
from typing import TypeAlias
|
|
4
|
+
|
|
5
|
+
_Constant: TypeAlias = bool | bytes | complex | EllipsisType | float | int | None | NotImplementedType | range | str
|
|
6
|
+
|
|
7
|
+
ConstantType: TypeAlias = _Constant | frozenset['ConstantType'] | tuple['ConstantType', ...]
|
|
8
|
+
|
|
9
|
+
def dump(
|
|
10
|
+
node: AST,
|
|
11
|
+
annotate_fields: bool = ...,
|
|
12
|
+
include_attributes: bool = ...,
|
|
13
|
+
*,
|
|
14
|
+
indent: int | str | None = ...,
|
|
15
|
+
show_empty: bool = ...,
|
|
16
|
+
) -> str:
|
|
17
|
+
def _format(node: ConstantType | AST | list[AST] | list[str], level: int = ...) -> tuple[str, bool]:
|
|
18
|
+
# Local variables in _format function
|
|
19
|
+
prefix: str
|
|
20
|
+
sep: str
|
|
21
|
+
cls: type[AST]
|
|
22
|
+
args: list[str]
|
|
23
|
+
args_buffer: list[str]
|
|
24
|
+
allsimple: bool
|
|
25
|
+
keywords: bool
|
|
26
|
+
|
|
27
|
+
name: str
|
|
28
|
+
value: AST | list[AST] | list[str] | ConstantType | bool | bytes | complex | float | int | str
|
|
29
|
+
value_formatted: str
|
|
30
|
+
simple: bool
|
|
31
|
+
|
|
32
|
+
name_attributes: str
|
|
33
|
+
value_attributes: int | None
|
|
34
|
+
value_attributes_formatted: str
|
|
35
|
+
|
|
36
|
+
x: AST | str
|
|
37
|
+
|
|
38
|
+
...
|
|
39
|
+
|
|
40
|
+
# Local variables in dump function
|
|
41
|
+
indent_str: str | None
|
|
42
|
+
|
|
43
|
+
...
|