py2dag 0.3.4__py3-none-any.whl → 0.3.5__py3-none-any.whl
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/parser.py +59 -38
- {py2dag-0.3.4.dist-info → py2dag-0.3.5.dist-info}/METADATA +1 -1
- {py2dag-0.3.4.dist-info → py2dag-0.3.5.dist-info}/RECORD +6 -6
- {py2dag-0.3.4.dist-info → py2dag-0.3.5.dist-info}/LICENSE +0 -0
- {py2dag-0.3.4.dist-info → py2dag-0.3.5.dist-info}/WHEEL +0 -0
- {py2dag-0.3.4.dist-info → py2dag-0.3.5.dist-info}/entry_points.txt +0 -0
py2dag/parser.py
CHANGED
@@ -343,26 +343,7 @@ def parse(source: str, function_name: Optional[str] = None) -> Dict[str, Any]:
|
|
343
343
|
sl = sl.value # type: ignore[assignment]
|
344
344
|
key = _literal(sl)
|
345
345
|
|
346
|
-
|
347
|
-
if isinstance(value, ast.Await):
|
348
|
-
value = value.value
|
349
|
-
awaited = True
|
350
|
-
|
351
|
-
# Determine SSA id for RHS value
|
352
|
-
if isinstance(value, ast.Call):
|
353
|
-
val_id = _emit_assign_from_call(f"{base.id}_item", value, awaited)
|
354
|
-
elif isinstance(value, ast.JoinedStr):
|
355
|
-
val_id = _emit_assign_from_fstring(f"{base.id}_item", value)
|
356
|
-
elif isinstance(value, (ast.Constant, ast.List, ast.Tuple, ast.Dict)):
|
357
|
-
val_id = _emit_assign_from_literal_or_pack(f"{base.id}_item", value)
|
358
|
-
elif isinstance(value, (ast.ListComp, ast.SetComp, ast.DictComp, ast.GeneratorExp)):
|
359
|
-
val_id = _emit_assign_from_comp(f"{base.id}_item", value)
|
360
|
-
elif isinstance(value, ast.Subscript):
|
361
|
-
val_id = _emit_assign_from_subscript(f"{base.id}_item", value)
|
362
|
-
elif isinstance(value, ast.Name):
|
363
|
-
val_id = _ssa_get(value.id)
|
364
|
-
else:
|
365
|
-
raise DSLParseError("Right hand side must be a call or f-string")
|
346
|
+
val_id = _emit_value(f"{base.id}_item", value)
|
366
347
|
|
367
348
|
base_id = _ssa_get(base.id)
|
368
349
|
ssa = _ssa_new(base.id)
|
@@ -381,6 +362,51 @@ def parse(source: str, function_name: Optional[str] = None) -> Dict[str, Any]:
|
|
381
362
|
ops.append({"id": ssa, "op": "COND.eval", "deps": deps, "args": {"expr": expr, "kind": kind}})
|
382
363
|
return ssa
|
383
364
|
|
365
|
+
def _emit_assign_from_ifexp(var_name: str, node: ast.IfExp) -> str:
|
366
|
+
"""Emit operations for an inline ``a if cond else b`` expression."""
|
367
|
+
cond_id = _emit_cond(node.test, kind="ifexp")
|
368
|
+
|
369
|
+
then_start = len(ops)
|
370
|
+
then_id = _emit_value(f"{var_name}_then", node.body)
|
371
|
+
if len(ops) > then_start:
|
372
|
+
first = ops[then_start]
|
373
|
+
deps0 = first.get("deps", []) or []
|
374
|
+
if cond_id not in deps0:
|
375
|
+
first["deps"] = [*deps0, cond_id]
|
376
|
+
|
377
|
+
else_start = len(ops)
|
378
|
+
else_id = _emit_value(f"{var_name}_else", node.orelse)
|
379
|
+
if len(ops) > else_start:
|
380
|
+
first = ops[else_start]
|
381
|
+
deps0 = first.get("deps", []) or []
|
382
|
+
if cond_id not in deps0:
|
383
|
+
first["deps"] = [*deps0, cond_id]
|
384
|
+
|
385
|
+
ssa = _ssa_new(var_name)
|
386
|
+
ops.append({"id": ssa, "op": "PHI", "deps": [then_id, else_id], "args": {"var": var_name}})
|
387
|
+
return ssa
|
388
|
+
|
389
|
+
def _emit_value(var_name: str, value: ast.AST) -> str:
|
390
|
+
awaited = False
|
391
|
+
if isinstance(value, ast.Await):
|
392
|
+
value = value.value
|
393
|
+
awaited = True
|
394
|
+
if isinstance(value, ast.Call):
|
395
|
+
return _emit_assign_from_call(var_name, value, awaited)
|
396
|
+
if isinstance(value, ast.JoinedStr):
|
397
|
+
return _emit_assign_from_fstring(var_name, value)
|
398
|
+
if isinstance(value, (ast.Constant, ast.List, ast.Tuple, ast.Dict)):
|
399
|
+
return _emit_assign_from_literal_or_pack(var_name, value)
|
400
|
+
if isinstance(value, (ast.ListComp, ast.SetComp, ast.DictComp, ast.GeneratorExp)):
|
401
|
+
return _emit_assign_from_comp(var_name, value)
|
402
|
+
if isinstance(value, ast.Subscript):
|
403
|
+
return _emit_assign_from_subscript(var_name, value)
|
404
|
+
if isinstance(value, ast.IfExp):
|
405
|
+
return _emit_assign_from_ifexp(var_name, value)
|
406
|
+
if isinstance(value, ast.Name):
|
407
|
+
return _ssa_get(value.id)
|
408
|
+
raise DSLParseError("Right hand side must be a call or f-string")
|
409
|
+
|
384
410
|
def _emit_iter(node: ast.AST, target_label: Optional[str] = None) -> str:
|
385
411
|
expr = _stringify(node)
|
386
412
|
deps = [_ssa_get(n) for n in _collect_value_deps(node)]
|
@@ -399,23 +425,7 @@ def parse(source: str, function_name: Optional[str] = None) -> Dict[str, Any]:
|
|
399
425
|
target = stmt.targets[0]
|
400
426
|
if isinstance(target, ast.Name):
|
401
427
|
var_name = target.id
|
402
|
-
|
403
|
-
awaited = False
|
404
|
-
if isinstance(value, ast.Await):
|
405
|
-
value = value.value
|
406
|
-
awaited = True
|
407
|
-
if isinstance(value, ast.Call):
|
408
|
-
return _emit_assign_from_call(var_name, value, awaited)
|
409
|
-
elif isinstance(value, ast.JoinedStr):
|
410
|
-
return _emit_assign_from_fstring(var_name, value)
|
411
|
-
elif isinstance(value, (ast.Constant, ast.List, ast.Tuple, ast.Dict)):
|
412
|
-
return _emit_assign_from_literal_or_pack(var_name, value)
|
413
|
-
elif isinstance(value, (ast.ListComp, ast.SetComp, ast.DictComp, ast.GeneratorExp)):
|
414
|
-
return _emit_assign_from_comp(var_name, value)
|
415
|
-
elif isinstance(value, ast.Subscript):
|
416
|
-
return _emit_assign_from_subscript(var_name, value)
|
417
|
-
else:
|
418
|
-
raise DSLParseError("Right hand side must be a call or f-string")
|
428
|
+
return _emit_value(var_name, stmt.value)
|
419
429
|
elif isinstance(target, ast.Subscript):
|
420
430
|
return _emit_assign_to_subscript(target, stmt.value)
|
421
431
|
else:
|
@@ -459,7 +469,18 @@ def parse(source: str, function_name: Optional[str] = None) -> Dict[str, Any]:
|
|
459
469
|
ssa = _ssa_new("break")
|
460
470
|
ops.append({"id": ssa, "op": "CTRL.break", "deps": [], "args": {}})
|
461
471
|
if isinstance(stmt.value, ast.Name):
|
462
|
-
|
472
|
+
name = stmt.value.id
|
473
|
+
if name in latest:
|
474
|
+
returned_var = _ssa_get(name)
|
475
|
+
else:
|
476
|
+
const_id = _ssa_new("return_value")
|
477
|
+
ops.append({
|
478
|
+
"id": const_id,
|
479
|
+
"op": "CONST.value",
|
480
|
+
"deps": [],
|
481
|
+
"args": {"value": None},
|
482
|
+
})
|
483
|
+
returned_var = const_id
|
463
484
|
elif isinstance(stmt.value, (ast.Constant, ast.List, ast.Tuple, ast.Dict)):
|
464
485
|
lit = _literal(stmt.value)
|
465
486
|
const_id = _ssa_new("return_value")
|
@@ -3,10 +3,10 @@ py2dag/cli.py,sha256=q8ocafpGtkrls1mx9QiFU1wL6KKeeJhT0Oklk6SwHB0,15151
|
|
3
3
|
py2dag/colors.py,sha256=kVMVWUKJY1uLQFQux5XKiEcofDFpNPQoAEzpMJWs2b0,604
|
4
4
|
py2dag/export_dagre.py,sha256=Og-oVjKzc7bRgeU7rgLHDjiY6wIcNyr2nIYlSAQzKoM,6041
|
5
5
|
py2dag/export_svg.py,sha256=3ZmZqxIUidSbuKIIh5kFqhfVnoqZ6PbEQpMih4AX9xo,3793
|
6
|
-
py2dag/parser.py,sha256=
|
6
|
+
py2dag/parser.py,sha256=HWmXK7lSmERL6HcP36KIMdNHU9jBWmum8VKz5G2Rp7k,35128
|
7
7
|
py2dag/pseudo.py,sha256=NJK61slyFLtSjhj8gJDJneUInEpBN57_41g8IfHNPWI,922
|
8
|
-
py2dag-0.3.
|
9
|
-
py2dag-0.3.
|
10
|
-
py2dag-0.3.
|
11
|
-
py2dag-0.3.
|
12
|
-
py2dag-0.3.
|
8
|
+
py2dag-0.3.5.dist-info/LICENSE,sha256=3Qee1EPwej_nusovTbyIQ8LvD2rXHdM0c6LNwk_D8Kc,1067
|
9
|
+
py2dag-0.3.5.dist-info/METADATA,sha256=msm0oyCl8_UVfxTVTUlRthioOuSxx3sx8K40FywRLQA,3549
|
10
|
+
py2dag-0.3.5.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
11
|
+
py2dag-0.3.5.dist-info/entry_points.txt,sha256=Q0SHexJJ0z1te4AYL1xTZogx5FrxCCE1ZJ5qntkFMZs,42
|
12
|
+
py2dag-0.3.5.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|