glom
glom copied to clipboard
better target-path
there was some prototyping of scope[Path]
as a mechanism for tracking target path, but there are some flaws and also it eats a lot of performance for light specs (e.g. list-of-dicts)
here are some of the issues:
- the path associates to the CHILD scope but lives in the parent; incremental path segments should be pushed down into the child
e.g. a very simple case:
glom([1, 1, 1], [T])
While evaluating the first T
, the list-scope will have path=0; the T-scope will have no path
When evaluating the second T
, the list-scope will have path=1; the T-scope will have no path
This really becomes a problem when something like branching gets introduced -- if you want to be able to "rewind" and generate a nice clean error message involving the target-path for why a previous branch failed it is impossible because that information got overwritten in the parent scope
one approach forward would be to add a param to _glom()
def _glom(target, spec, scope, target_move=_MISSING):
if target_move is not _MISSING:
scope[Path] = target_move
or similar -- storing something in the scope that says "here is how the current target was derived from the previous target"
possibly something that also requires looking at the spec to interpret