glom
glom copied to clipboard
Improved error checking of "scope" param on Spec constructor.
Each one of those two spec work separately.
from glom import Spec, T, glom
d = {'a': [1, {'b': 2}, 3], 'c': {'d': [4, 5]}}
spec = Spec(T['a'][1]['b'], T['c']['d'][1])
print(glom(d, spec))
Ah, this is because the second argument to the Spec
constructor is meant to be a "scope" (a concept not yet well-documented, but akin to function scope, but for specs). Since the T
object is very permissive, it can cause some interesting error conditions when used outside of places that expect T
.
I wonder if we can do any checking on the scope argument in the Spec constructor to fix this in future.
And not to speculate too much, but if you wanted a tuple of these two values, I'd probably just do two separate glom alls for now. We're working on a design for a sequence builder specifier type, but for now two calls shouldn't be too bad, eh? :)
Yes you got it. I was trying to solve https://github.com/mahmoud/glom/issues/77, then I stumble upon this case that make an infinite loop. Just wanted to signal an uncaught error case.
Appreciate it! I'll leave this issue open in case we can improve the Scope error handling.