py2dag 0.3.1__py3-none-any.whl → 0.3.3__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 CHANGED
@@ -62,7 +62,7 @@ def parse(source: str, function_name: Optional[str] = None) -> Dict[str, Any]:
62
62
  versions: Dict[str, int] = {}
63
63
  latest: Dict[str, str] = {}
64
64
  context_suffix: str = ""
65
- ctx_counts: Dict[str, int] = {"if": 0, "loop": 0, "while": 0}
65
+ ctx_counts: Dict[str, int] = {"if": 0, "loop": 0, "while": 0, "except": 0}
66
66
 
67
67
  def _ssa_new(name: str) -> str:
68
68
  if not VALID_NAME_RE.match(name):
@@ -108,7 +108,7 @@ def parse(source: str, function_name: Optional[str] = None) -> Dict[str, Any]:
108
108
  deps: List[str] = []
109
109
  for n in ast.walk(node):
110
110
  if isinstance(n, ast.Name) and isinstance(n.ctx, ast.Load):
111
- if n.id not in callees and n.id not in deps:
111
+ if n.id not in callees and n.id not in deps and n.id in latest:
112
112
  deps.append(n.id)
113
113
  return deps
114
114
 
@@ -593,6 +593,29 @@ def parse(source: str, function_name: Optional[str] = None) -> Dict[str, Any]:
593
593
  "args": {"var": var},
594
594
  })
595
595
  return None
596
+ elif isinstance(stmt, ast.Try):
597
+ pre_versions = dict(versions)
598
+ pre_latest = dict(latest)
599
+ for inner in stmt.body:
600
+ _parse_stmt(inner)
601
+ # else block executes only if no exception
602
+ for inner in getattr(stmt, "orelse", []):
603
+ _parse_stmt(inner)
604
+ post_versions = versions
605
+ post_latest = latest
606
+ for handler in getattr(stmt, "handlers", []):
607
+ saved_ctx = context_suffix
608
+ ctx_counts["except"] = ctx_counts.get("except", 0) + 1
609
+ context_suffix = f"except{ctx_counts['except']}"
610
+ saved_versions, saved_latest = versions, latest
611
+ versions, latest = dict(pre_versions), dict(pre_latest)
612
+ for inner in handler.body:
613
+ _parse_stmt(inner)
614
+ versions, latest = post_versions, post_latest
615
+ context_suffix = saved_ctx
616
+ for inner in getattr(stmt, "finalbody", []):
617
+ _parse_stmt(inner)
618
+ return None
596
619
  elif isinstance(stmt, ast.Break):
597
620
  ssa = _ssa_new("break")
598
621
  ops.append({"id": ssa, "op": "CTRL.break", "deps": [], "args": {}})
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: py2dag
3
- Version: 0.3.1
3
+ Version: 0.3.3
4
4
  Summary: Convert Python function plans to DAG (JSON, pseudo, optional SVG).
5
5
  License: MIT
6
6
  Author: rvergis
@@ -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=bpwOZVsJUS3fRQTFfm2CfTxqlTWUYaLYDOHJRA2Yj34,30657
6
+ py2dag/parser.py,sha256=WN2ZbOZdc05mOr60Q-IDA9TPsTX6tKb_VuDdBEBFeq8,31862
7
7
  py2dag/pseudo.py,sha256=NJK61slyFLtSjhj8gJDJneUInEpBN57_41g8IfHNPWI,922
8
- py2dag-0.3.1.dist-info/LICENSE,sha256=3Qee1EPwej_nusovTbyIQ8LvD2rXHdM0c6LNwk_D8Kc,1067
9
- py2dag-0.3.1.dist-info/METADATA,sha256=GhuNW_nWmz0P0eNjX6Zs2y65AglkhUT1lplPeDzxmaU,3549
10
- py2dag-0.3.1.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
11
- py2dag-0.3.1.dist-info/entry_points.txt,sha256=Q0SHexJJ0z1te4AYL1xTZogx5FrxCCE1ZJ5qntkFMZs,42
12
- py2dag-0.3.1.dist-info/RECORD,,
8
+ py2dag-0.3.3.dist-info/LICENSE,sha256=3Qee1EPwej_nusovTbyIQ8LvD2rXHdM0c6LNwk_D8Kc,1067
9
+ py2dag-0.3.3.dist-info/METADATA,sha256=Y6H9SC22ONmNes0_2ELcSAOtJlbsEpXKr0lzi2f2zss,3549
10
+ py2dag-0.3.3.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
11
+ py2dag-0.3.3.dist-info/entry_points.txt,sha256=Q0SHexJJ0z1te4AYL1xTZogx5FrxCCE1ZJ5qntkFMZs,42
12
+ py2dag-0.3.3.dist-info/RECORD,,
File without changes