py2dag 0.2.3__tar.gz → 0.2.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: py2dag
3
- Version: 0.2.3
3
+ Version: 0.2.4
4
4
  Summary: Convert Python function plans to DAG (JSON, pseudo, optional SVG).
5
5
  License: MIT
6
6
  Author: rvergis
@@ -288,6 +288,26 @@ def parse(source: str, function_name: Optional[str] = None) -> Dict[str, Any]:
288
288
  })
289
289
  return ssa
290
290
 
291
+ def _emit_assign_from_subscript(var_name: str, node: ast.Subscript) -> str:
292
+ # Support name[key] where key is a JSON-serialisable literal
293
+ base = node.value
294
+ if not isinstance(base, ast.Name):
295
+ raise DSLParseError("Subscript base must be a variable name")
296
+ # Extract slice expression across Python versions
297
+ sl = getattr(node, 'slice', None)
298
+ # In Python >=3.9, slice is the actual node; before it may be ast.Index
299
+ if hasattr(ast, 'Index') and isinstance(sl, getattr(ast, 'Index')): # type: ignore[attr-defined]
300
+ sl = sl.value # type: ignore[assignment]
301
+ key = _literal(sl) # may raise if not literal
302
+ ssa = _ssa_new(var_name)
303
+ ops.append({
304
+ "id": ssa,
305
+ "op": "GET.item",
306
+ "deps": [_ssa_get(base.id)],
307
+ "args": {"key": key},
308
+ })
309
+ return ssa
310
+
291
311
  def _emit_cond(node: ast.AST, kind: str = "if") -> str:
292
312
  expr = _stringify(node)
293
313
  deps = [_ssa_get(n) for n in _collect_value_deps(node)]
@@ -322,6 +342,8 @@ def parse(source: str, function_name: Optional[str] = None) -> Dict[str, Any]:
322
342
  return _emit_assign_from_literal_or_pack(var_name, value)
323
343
  elif isinstance(value, (ast.ListComp, ast.SetComp, ast.DictComp, ast.GeneratorExp)):
324
344
  return _emit_assign_from_comp(var_name, value)
345
+ elif isinstance(value, ast.Subscript):
346
+ return _emit_assign_from_subscript(var_name, value)
325
347
  else:
326
348
  raise DSLParseError("Right hand side must be a call or f-string")
327
349
  elif isinstance(stmt, ast.Expr):
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
4
4
 
5
5
  [tool.poetry]
6
6
  name = "py2dag"
7
- version = "0.2.3"
7
+ version = "0.2.4"
8
8
  description = "Convert Python function plans to DAG (JSON, pseudo, optional SVG)."
9
9
  authors = ["rvergis"]
10
10
  license = "MIT"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes