astToolkit 0.3.3__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.
Files changed (32) hide show
  1. {asttoolkit-0.3.3 → asttoolkit-0.3.5}/PKG-INFO +1 -3
  2. {asttoolkit-0.3.3 → asttoolkit-0.3.5}/astToolkit/__init__.py +2 -0
  3. {asttoolkit-0.3.3 → asttoolkit-0.3.5}/astToolkit/_astTypes.py +22 -3
  4. asttoolkit-0.3.5/astToolkit/_dumpFunctionDef.py +76 -0
  5. asttoolkit-0.3.5/astToolkit/_joinClassmethod.py +586 -0
  6. {asttoolkit-0.3.3 → asttoolkit-0.3.5}/astToolkit/_theSSOT.py +4 -4
  7. {asttoolkit-0.3.3 → asttoolkit-0.3.5}/astToolkit/_toolBe.py +11 -12
  8. {asttoolkit-0.3.3 → asttoolkit-0.3.5}/astToolkit/_toolClassIsAndAttribute.py +13 -13
  9. {asttoolkit-0.3.3 → asttoolkit-0.3.5}/astToolkit/_toolDOT.py +36 -37
  10. {asttoolkit-0.3.3 → asttoolkit-0.3.5}/astToolkit/_toolGrab.py +23 -24
  11. {asttoolkit-0.3.3 → asttoolkit-0.3.5}/astToolkit/_toolMake.py +134 -119
  12. {asttoolkit-0.3.3 → asttoolkit-0.3.5}/astToolkit/_toolkitAST.py +6 -11
  13. {asttoolkit-0.3.3 → asttoolkit-0.3.5}/astToolkit/_types.py +1 -2
  14. {asttoolkit-0.3.3 → asttoolkit-0.3.5}/astToolkit.egg-info/PKG-INFO +1 -3
  15. {asttoolkit-0.3.3 → asttoolkit-0.3.5}/astToolkit.egg-info/SOURCES.txt +1 -0
  16. {asttoolkit-0.3.3 → asttoolkit-0.3.5}/pyproject.toml +1 -3
  17. asttoolkit-0.3.3/astToolkit/_joinClassmethod.py +0 -1260
  18. {asttoolkit-0.3.3 → asttoolkit-0.3.5}/LICENSE +0 -0
  19. {asttoolkit-0.3.3 → asttoolkit-0.3.5}/README.md +0 -0
  20. {asttoolkit-0.3.3 → asttoolkit-0.3.5}/astToolkit/_toolIfThis.py +0 -0
  21. {asttoolkit-0.3.3 → asttoolkit-0.3.5}/astToolkit/_toolThen.py +0 -0
  22. {asttoolkit-0.3.3 → asttoolkit-0.3.5}/astToolkit/_toolkitContainers.py +0 -0
  23. {asttoolkit-0.3.3 → asttoolkit-0.3.5}/astToolkit/_toolkitNodeVisitor.py +0 -0
  24. {asttoolkit-0.3.3 → asttoolkit-0.3.5}/astToolkit/py.typed +0 -0
  25. {asttoolkit-0.3.3 → asttoolkit-0.3.5}/astToolkit/transformationTools.py +0 -0
  26. {asttoolkit-0.3.3 → asttoolkit-0.3.5}/astToolkit.egg-info/dependency_links.txt +0 -0
  27. {asttoolkit-0.3.3 → asttoolkit-0.3.5}/astToolkit.egg-info/requires.txt +0 -0
  28. {asttoolkit-0.3.3 → asttoolkit-0.3.5}/astToolkit.egg-info/top_level.txt +0 -0
  29. {asttoolkit-0.3.3 → asttoolkit-0.3.5}/setup.cfg +0 -0
  30. {asttoolkit-0.3.3 → asttoolkit-0.3.5}/tests/conftest.py +0 -0
  31. {asttoolkit-0.3.3 → asttoolkit-0.3.5}/tests/test_basic.py +0 -0
  32. {asttoolkit-0.3.3 → 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
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
@@ -28,6 +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
32
+
31
33
  from astToolkit._toolkitNodeVisitor import (
32
34
  NodeChanger as NodeChanger,
33
35
  NodeTourist as NodeTourist,
@@ -1,13 +1,32 @@
1
1
  """This file is generated automatically, so changes to this file will be lost."""
2
- from typing import Any, TypeAlias as typing_TypeAlias, TypeVar as typing_TypeVar
2
+ from types import EllipsisType, NotImplementedType
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)
15
+
16
+ class _attributes(TypedDict, total=False):
17
+ lineno: int
18
+ col_offset: int
19
+
20
+ class ast_attributes(_attributes, total=False):
21
+ end_lineno: int | None
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
11
30
  hasDOTannotation_expr: typing_TypeAlias = ast.AnnAssign
12
31
  hasDOTannotation_exprOrNone: typing_TypeAlias = ast.arg
13
32
  hasDOTannotation: typing_TypeAlias = hasDOTannotation_expr | hasDOTannotation_exprOrNone
@@ -111,10 +130,10 @@ hasDOTtype_comment: typing_TypeAlias = ast.arg | ast.Assign | ast.AsyncFor | ast
111
130
  hasDOTtype_ignores: typing_TypeAlias = ast.Module
112
131
  hasDOTtype_params: typing_TypeAlias = ast.AsyncFunctionDef | ast.ClassDef | ast.FunctionDef | ast.TypeAlias
113
132
  hasDOTupper: typing_TypeAlias = ast.Slice
114
- hasDOTvalue_Any: typing_TypeAlias = ast.Constant
133
+ hasDOTvalue_ScalarOrContainerOfScalar: typing_TypeAlias = ast.Constant
115
134
  hasDOTvalue_boolOrNone: typing_TypeAlias = ast.MatchSingleton
116
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
117
136
  hasDOTvalue_exprOrNone: typing_TypeAlias = ast.AnnAssign | ast.Return | ast.Yield
118
- hasDOTvalue: typing_TypeAlias = hasDOTvalue_Any | hasDOTvalue_boolOrNone | hasDOTvalue_expr | hasDOTvalue_exprOrNone
137
+ hasDOTvalue: typing_TypeAlias = hasDOTvalue_ScalarOrContainerOfScalar | hasDOTvalue_boolOrNone | hasDOTvalue_expr | hasDOTvalue_exprOrNone
119
138
  hasDOTvalues: typing_TypeAlias = ast.BoolOp | ast.Dict | ast.JoinedStr
120
139
  hasDOTvararg: typing_TypeAlias = ast.arguments
@@ -0,0 +1,76 @@
1
+ from _ast import *
2
+
3
+ def dump(node, annotate_fields=True, include_attributes=False, *, indent=None, show_empty=False):
4
+ """
5
+ Return a formatted dump of the tree in node. This is mainly useful for
6
+ debugging purposes. If annotate_fields is true (by default),
7
+ the returned string will show the names and the values for fields.
8
+ If annotate_fields is false, the result string will be more compact by
9
+ omitting unambiguous field names. Attributes such as line
10
+ numbers and column offsets are not dumped by default. If this is wanted,
11
+ include_attributes can be set to true. If indent is a non-negative
12
+ integer or string, then the tree will be pretty-printed with that indent
13
+ level. None (the default) selects the single line representation.
14
+ If show_empty is False, then empty lists and fields that are None
15
+ will be omitted from the output for better readability.
16
+ """
17
+
18
+ def _format(node, level=0):
19
+ if indent is not None:
20
+ level += 1
21
+ prefix = '\n' + indent * level
22
+ sep = ',\n' + indent * level
23
+ else:
24
+ prefix = ''
25
+ sep = ', '
26
+ if isinstance(node, AST):
27
+ cls = type(node)
28
+ args = []
29
+ args_buffer = []
30
+ allsimple = True
31
+ keywords = annotate_fields
32
+ for name in node._fields:
33
+ try:
34
+ value = getattr(node, name)
35
+ except AttributeError:
36
+ keywords = True
37
+ continue
38
+ if value is None and getattr(cls, name, ...) is None:
39
+ keywords = True
40
+ continue
41
+ if not show_empty and (value is None or value == []) and (not isinstance(node, (Constant, MatchSingleton))):
42
+ args_buffer.append(repr(value))
43
+ continue
44
+ elif not keywords:
45
+ args.extend(args_buffer)
46
+ args_buffer = []
47
+ value, simple = _format(value, level)
48
+ allsimple = allsimple and simple
49
+ if keywords:
50
+ args.append('%s=%s' % (name, value))
51
+ else:
52
+ args.append(value)
53
+ if include_attributes and node._attributes:
54
+ for name in node._attributes:
55
+ try:
56
+ value = getattr(node, name)
57
+ except AttributeError:
58
+ continue
59
+ if value is None and getattr(cls, name, ...) is None:
60
+ continue
61
+ value, simple = _format(value, level)
62
+ allsimple = allsimple and simple
63
+ args.append('%s=%s' % (name, value))
64
+ if allsimple and len(args) <= 3:
65
+ return ('%s(%s)' % ('ast.' + node.__class__.__name__, ', '.join(args)), not args)
66
+ return ('%s(%s%s)' % ('ast.' + node.__class__.__name__, prefix, sep.join(args)), False)
67
+ elif isinstance(node, list):
68
+ if not node:
69
+ return ('[]', True)
70
+ return ('[%s%s]' % (prefix, sep.join((_format(x, level)[0] for x in node))), False)
71
+ return (repr(node), True)
72
+ if not isinstance(node, AST):
73
+ raise TypeError('expected AST, got %r' % node.__class__.__name__)
74
+ if indent is not None and (not isinstance(indent, str)):
75
+ indent = ' ' * indent
76
+ return _format(node)[0]