astToolkit 0.3.3__tar.gz → 0.3.4__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 (31) hide show
  1. {asttoolkit-0.3.3 → asttoolkit-0.3.4}/PKG-INFO +1 -1
  2. {asttoolkit-0.3.3 → asttoolkit-0.3.4}/astToolkit/__init__.py +2 -0
  3. {asttoolkit-0.3.3 → asttoolkit-0.3.4}/astToolkit/_astTypes.py +7 -1
  4. asttoolkit-0.3.4/astToolkit/_dumpFunctionDef.py +76 -0
  5. {asttoolkit-0.3.3 → asttoolkit-0.3.4}/astToolkit/_toolBe.py +0 -1
  6. {asttoolkit-0.3.3 → asttoolkit-0.3.4}/astToolkit/_toolkitAST.py +6 -11
  7. {asttoolkit-0.3.3 → asttoolkit-0.3.4}/astToolkit/_types.py +1 -2
  8. {asttoolkit-0.3.3 → asttoolkit-0.3.4}/astToolkit.egg-info/PKG-INFO +1 -1
  9. {asttoolkit-0.3.3 → asttoolkit-0.3.4}/astToolkit.egg-info/SOURCES.txt +1 -0
  10. {asttoolkit-0.3.3 → asttoolkit-0.3.4}/pyproject.toml +1 -1
  11. {asttoolkit-0.3.3 → asttoolkit-0.3.4}/LICENSE +0 -0
  12. {asttoolkit-0.3.3 → asttoolkit-0.3.4}/README.md +0 -0
  13. {asttoolkit-0.3.3 → asttoolkit-0.3.4}/astToolkit/_joinClassmethod.py +0 -0
  14. {asttoolkit-0.3.3 → asttoolkit-0.3.4}/astToolkit/_theSSOT.py +0 -0
  15. {asttoolkit-0.3.3 → asttoolkit-0.3.4}/astToolkit/_toolClassIsAndAttribute.py +0 -0
  16. {asttoolkit-0.3.3 → asttoolkit-0.3.4}/astToolkit/_toolDOT.py +0 -0
  17. {asttoolkit-0.3.3 → asttoolkit-0.3.4}/astToolkit/_toolGrab.py +0 -0
  18. {asttoolkit-0.3.3 → asttoolkit-0.3.4}/astToolkit/_toolIfThis.py +0 -0
  19. {asttoolkit-0.3.3 → asttoolkit-0.3.4}/astToolkit/_toolMake.py +0 -0
  20. {asttoolkit-0.3.3 → asttoolkit-0.3.4}/astToolkit/_toolThen.py +0 -0
  21. {asttoolkit-0.3.3 → asttoolkit-0.3.4}/astToolkit/_toolkitContainers.py +0 -0
  22. {asttoolkit-0.3.3 → asttoolkit-0.3.4}/astToolkit/_toolkitNodeVisitor.py +0 -0
  23. {asttoolkit-0.3.3 → asttoolkit-0.3.4}/astToolkit/py.typed +0 -0
  24. {asttoolkit-0.3.3 → asttoolkit-0.3.4}/astToolkit/transformationTools.py +0 -0
  25. {asttoolkit-0.3.3 → asttoolkit-0.3.4}/astToolkit.egg-info/dependency_links.txt +0 -0
  26. {asttoolkit-0.3.3 → asttoolkit-0.3.4}/astToolkit.egg-info/requires.txt +0 -0
  27. {asttoolkit-0.3.3 → asttoolkit-0.3.4}/astToolkit.egg-info/top_level.txt +0 -0
  28. {asttoolkit-0.3.3 → asttoolkit-0.3.4}/setup.cfg +0 -0
  29. {asttoolkit-0.3.3 → asttoolkit-0.3.4}/tests/conftest.py +0 -0
  30. {asttoolkit-0.3.3 → asttoolkit-0.3.4}/tests/test_basic.py +0 -0
  31. {asttoolkit-0.3.3 → asttoolkit-0.3.4}/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.4
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
@@ -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,5 +1,5 @@
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 typing import Any, TypeAlias as typing_TypeAlias, TypedDict, TypeVar as typing_TypeVar
3
3
  import ast
4
4
  import sys
5
5
  intORstr: typing_TypeAlias = Any
@@ -8,6 +8,12 @@ intORtype_params: typing_TypeAlias = Any
8
8
  木 = typing_TypeVar('木', bound=ast.AST, covariant=True)
9
9
  个 = typing_TypeVar('个', covariant=True)
10
10
  个return = typing_TypeVar('个return', covariant=True)
11
+
12
+ class ast_attributes(TypedDict, total=False):
13
+ lineno: int
14
+ col_offset: int
15
+ end_lineno: int | None
16
+ end_col_offset: int | None
11
17
  hasDOTannotation_expr: typing_TypeAlias = ast.AnnAssign
12
18
  hasDOTannotation_exprOrNone: typing_TypeAlias = ast.arg
13
19
  hasDOTannotation: typing_TypeAlias = hasDOTannotation_expr | hasDOTannotation_exprOrNone
@@ -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]
@@ -1,7 +1,6 @@
1
1
  """This file is generated automatically, so changes to this file will be lost."""
2
2
  from typing import TypeGuard
3
3
  import ast
4
- import sys
5
4
 
6
5
  class Be:
7
6
  """
@@ -22,9 +22,6 @@ def astModuleToIngredientsFunction(astModule: ast.AST, identifierFunctionDef: st
22
22
  Returns:
23
23
  ingredientsFunction: `IngredientsFunction` object containing the `ast.FunctionDef` and _all_ imports from the
24
24
  source module.
25
-
26
- Raises:
27
- FREAKOUT: If the function definition is not found.
28
25
  """
29
26
  astFunctionDef = raiseIfNone(extractFunctionDef(astModule, identifierFunctionDef))
30
27
  return IngredientsFunction(astFunctionDef, LedgerOfImports(astModule))
@@ -74,10 +71,9 @@ def parseLogicalPath2astModule(logicalPathModule: str_nameDOTname, packageIdenti
74
71
  The logical path to the module using dot notation (e.g., 'package.module').
75
72
  packageIdentifierIfRelative : None
76
73
  The package identifier to use if the module path is relative, defaults to None.
77
- mode : Literal['exec']
78
- The mode parameter for `ast.parse`. Default is `Literal['exec']`. Options are `Literal['exec']`, `"exec"` (which
79
- is _not_ the same as `Literal['exec']`), `Literal['eval']`, `Literal['func_type']`, `Literal['single']`. See
80
- `ast.parse` documentation for some details and much confusion.
74
+ mode : 'exec'
75
+ The mode parameter for `ast.parse`. Default is `'exec'`. Options are `'exec'`, `'eval'`, `'func_type'`, `'single'`. See
76
+ `ast.parse` documentation.
81
77
 
82
78
  Returns
83
79
  -------
@@ -99,10 +95,9 @@ def parsePathFilename2astModule(pathFilename: PathLike[Any] | PurePath, mode: Li
99
95
  ----------
100
96
  pathFilename
101
97
  The path to the file to be parsed. Can be a string path, PathLike object, or PurePath object.
102
- mode : Literal['exec']
103
- The mode parameter for `ast.parse`. Default is `Literal['exec']`. Options are `Literal['exec']`, `"exec"` (which
104
- is _not_ the same as `Literal['exec']`), `Literal['eval']`, `Literal['func_type']`, `Literal['single']`. See
105
- `ast.parse` documentation for some details and much confusion.
98
+ mode : 'exec'
99
+ The mode parameter for `ast.parse`. Default is `'exec'`. Options are `'exec'`, `'eval'`, `'func_type'`, `'single'`. See
100
+ `ast.parse` documentation.
106
101
 
107
102
  Returns
108
103
  -------
@@ -1,6 +1,5 @@
1
- from typing import Any, TypeAlias as typing_TypeAlias, TypeVar as typing_TypeVar
1
+ from typing import TypeAlias as typing_TypeAlias
2
2
  import ast
3
- import sys
4
3
 
5
4
  # Type hints through TypeAlias or type "hints" through the identifier name.
6
5
  str_nameDOTname: typing_TypeAlias = str
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: astToolkit
3
- Version: 0.3.3
3
+ Version: 0.3.4
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
@@ -3,6 +3,7 @@ README.md
3
3
  pyproject.toml
4
4
  astToolkit/__init__.py
5
5
  astToolkit/_astTypes.py
6
+ astToolkit/_dumpFunctionDef.py
6
7
  astToolkit/_joinClassmethod.py
7
8
  astToolkit/_theSSOT.py
8
9
  astToolkit/_toolBe.py
@@ -36,7 +36,7 @@ optional-dependencies = { testing = [
36
36
  readme = { file = "README.md", content-type = "text/markdown" }
37
37
  requires-python = ">=3.12"
38
38
  urls = { Donate = "https://www.patreon.com/integrated", Homepage = "https://github.com/hunterhogan/astToolkit", Issues = "https://github.com/hunterhogan/astToolkit/issues", Repository = "https://github.com/hunterhogan/astToolkit.git" }
39
- version = "0.3.3"
39
+ version = "0.3.4"
40
40
 
41
41
  [tool.coverage]
42
42
  report = { exclude_lines = [
File without changes
File without changes
File without changes
File without changes