-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scope usage changes from v22 to v23 #259
Comments
Ah yeah this looks related to the arg-mode update (#196). You can get the old behavior with Previous to arg mode, the default interpretation of |
Could you give more context on what you use that for? You can get back the old behavior via explicit mode ( >>> import glom
>>> from glom import S, glom, Auto
>>> target = {'data': {'val': 9}}
>>> glom(target, (S(value = ('data', 'val')), S.value))
('data', 'val')
>>> glom(target, (S(value = Auto(('data', 'val'))), S.value))
9
>>> glom(target, (S(value = T['data']['val']), S.value))
9 The assumption is the more common case is building an intermediate data structure. Also, I'd be curious what your use case is where you are finding (
{
'val': ('data', 'val'),
'other_val': ...
},
'val'
) There's probably a gap in documentation that this came out of nowhere for you -- hopefully it wasn't too painful to figure out. |
I am unclear what you mean by build a dictionary to hold temporary values in parallel. My more specific use case is something like in (v22 style): target = ...
path = (
S(id=("id",)),
S(contract_type=("contract", "type"),
("receipts", [
{
"id": S.id,
"contract_type": S.contract_type,
"amount": ("amount",),
"from": ("sender", "id"),
}
])
) Hope this clears up my exact usage more or less. |
Got it. A great use of scope if I've ever seen one. To extrapolate your point, @DamianBarabonkovQC, and let me know if I'm wrong, but are you saying that when you use If so, I can see that point. If one were to want a literal during execution, there are several ways to get one, without using (btw, @DamianBarabonkovQC, what do you say to using the |
So I gave you an overly simplified example. Actually, my scope path is wrapped in a |
path = (
S(id=("id",)),
S(contract_type=("contract", "type"),
("receipts", [
{
"id": S.id,
"contract_type": S.contract_type,
"amount": ("amount",),
"from": ("sender", "id"),
}
])
) Oh, I see the challenge, you want to apply the outer values across each element of receipts. There's a few ways of doing that but none of them are cleaner than your current approach. I'd recommend switching to path = (
S(id=T["id"], contract_type=T["contract"]["type"]),
"receipts",
[{
"id": S.id,
"contract_type": S.contract_type,
"amount": "amount",
"from": "sender.id",
}]
) I agree with your approach -- this is the type of case Some other simplifications we can make:
Those might be necessary in the original spec and have become redundant when you simplified it down here |
Coming here to +1 the behavior change. Revisiting an old project in a new venv and spent 30mins debugging what the heck went wrong. 😅
I swapped many implicit references to use |
In glom v22, I was able to assign a scope with a spec and that automatically got applied to the target. Version 23 breaks that.
For example, this code used to work in v22:
However, in v23
The previous behavior of v22 is infinitely more helpful than this new usage. Unless this was an intentional breaking change, I am filing this issue to recommend that we revert to the old behavior.
The text was updated successfully, but these errors were encountered: