py2dag 0.3.6__tar.gz → 0.3.8__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.
- {py2dag-0.3.6 → py2dag-0.3.8}/PKG-INFO +1 -1
- {py2dag-0.3.6 → py2dag-0.3.8}/py2dag/parser.py +35 -4
- {py2dag-0.3.6 → py2dag-0.3.8}/pyproject.toml +1 -1
- {py2dag-0.3.6 → py2dag-0.3.8}/LICENSE +0 -0
- {py2dag-0.3.6 → py2dag-0.3.8}/README.md +0 -0
- {py2dag-0.3.6 → py2dag-0.3.8}/py2dag/__init__.py +0 -0
- {py2dag-0.3.6 → py2dag-0.3.8}/py2dag/cli.py +0 -0
- {py2dag-0.3.6 → py2dag-0.3.8}/py2dag/colors.py +0 -0
- {py2dag-0.3.6 → py2dag-0.3.8}/py2dag/export_dagre.py +0 -0
- {py2dag-0.3.6 → py2dag-0.3.8}/py2dag/export_svg.py +0 -0
- {py2dag-0.3.6 → py2dag-0.3.8}/py2dag/pseudo.py +0 -0
@@ -14,6 +14,20 @@ def _literal(node: ast.AST) -> Any:
|
|
14
14
|
"""Return a Python literal from an AST node or raise DSLParseError."""
|
15
15
|
if isinstance(node, ast.Constant):
|
16
16
|
return node.value
|
17
|
+
if isinstance(node, ast.JoinedStr):
|
18
|
+
parts: List[str] = []
|
19
|
+
for value in node.values:
|
20
|
+
if isinstance(value, ast.Constant):
|
21
|
+
parts.append(str(value.value))
|
22
|
+
elif isinstance(value, ast.FormattedValue):
|
23
|
+
try:
|
24
|
+
expr = ast.unparse(value.value) # type: ignore[attr-defined]
|
25
|
+
except Exception:
|
26
|
+
expr = "?"
|
27
|
+
parts.append("{" + expr + "}")
|
28
|
+
else:
|
29
|
+
raise DSLParseError("Keyword argument values must be JSON-serialisable literals")
|
30
|
+
return "".join(parts)
|
17
31
|
if isinstance(node, (ast.List, ast.Tuple)):
|
18
32
|
return [_literal(elt) for elt in node.elts]
|
19
33
|
if isinstance(node, ast.Dict):
|
@@ -722,11 +736,28 @@ def parse(source: str, function_name: Optional[str] = None) -> Dict[str, Any]:
|
|
722
736
|
for stmt in body:
|
723
737
|
_parse_stmt(stmt)
|
724
738
|
|
739
|
+
# If no explicit return was encountered, emit a terminal break node so
|
740
|
+
# that the plan represents function completion.
|
741
|
+
break_id: Optional[str] = None
|
742
|
+
if returned_var is None:
|
743
|
+
break_id = _ssa_new("break")
|
744
|
+
ops.append({"id": break_id, "op": "CTRL.break", "deps": [], "args": {}})
|
745
|
+
|
746
|
+
# If no outputs were produced, synthesise a default return of `None` so
|
747
|
+
# that parsing succeeds for empty functions.
|
748
|
+
if returned_var is None and not outputs:
|
749
|
+
const_id = _ssa_new("return_value")
|
750
|
+
ops.append({
|
751
|
+
"id": const_id,
|
752
|
+
"op": "CONST.value",
|
753
|
+
"deps": [],
|
754
|
+
"args": {"value": None},
|
755
|
+
})
|
756
|
+
returned_var = const_id
|
757
|
+
|
725
758
|
if not outputs:
|
726
|
-
if returned_var is not None:
|
727
|
-
|
728
|
-
else:
|
729
|
-
raise DSLParseError("At least one output() call required")
|
759
|
+
outputs.append({"from": returned_var if returned_var is not None else break_id, "as": "return"})
|
760
|
+
|
730
761
|
if len(ops) > 2000:
|
731
762
|
raise DSLParseError("Too many operations")
|
732
763
|
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|