-
Notifications
You must be signed in to change notification settings - Fork 116
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
Feature: nested string interpolations #610
Comments
String interpolations does not support nested interpolations right now. @Jasha10, do you have an actual use case or are you just pointing it out because it surprised you? |
IIRC at some point you mentioned that there was no need to support it so it's not something I kept -- pretty sure it was possible in one of my many versions :) There are some workarounds in case someone really needs it: # Use an intermediate variable to hold the full name
cfg = OmegaConf.create(
{
"a_ref": "b_${c}",
"a": "${${a_ref}}",
"c": 123,
"b_123": "xyz",
}
)
print(cfg.a) # Use a resolver
OmegaConf.register_new_resolver("identity", lambda x: x)
cfg = OmegaConf.create(
{
"a": "${${identity:b_${c}}}",
"c": 123,
"b_123": "xyz",
}
)
print(cfg.a) In terms of enabling it in the grammar, it wouldn't be too hard, it just wouldn't play nice with #600 => would need to change a bit the approach taken here (handling |
Yes, I do have a use case. I'll try to come up with a minimal practical example... Edit: for future reference, here is my motivating example: @dataclass
class Config:
provider: str # provider1 or provider2
service: str # serviceA or serviceB
message_format: str = "${message_format_table.${provider}_${service}}"
message_format_table: Dict[str, str] = ... |
Yeah yeah, blame me. If anyone wants to try to enable it go ahead but I am learning toward revisiting in 2.2. |
I wasn't aware that this was possible. Thanks for the tip! |
Not going for it myself but @Jasha10 if you want to take a stab at it let me know, I'll give you some pointers. |
Ok, sounds good :) Edit: just reread the above, I think revisiting in 2.2 sounds better given that there exist viable workarounds. |
Currently nested interpolations, e.g.
"${b_${c}}"
, do not seem to be supported.Here is an example:
The desired output would be
xyz
.The current behavior is to throw a
GrammarParserError
.Describe alternatives you've considered
Here is a workaround that uses
getattr
to explicitly dereference the interpolation:Additional context
The text was updated successfully, but these errors were encountered: