Closed markcoletti closed 10 months ago
Passing fake value should work ?
${cpus:temp}
OmegaConf.register_new_resolver("cpus", lambda x : os.cpu_count)
That's a kludge that works but is a bit ugly. It'd be cleaner and more intuitive if the package supports my original intent.
I'd love to have this feature too. If you are open to PR's and can give me a rough sketch of what will be impacted in the code, I can give it a try.
I just tried it and this is working => closing the issue (please re-open with a specific example if the issue still persists on your side)
Hi, I'm trying to use custom resolvers with no params and I'm hitting the same issue reported here. Minimal reproducible example:
import random
from omegaconf import OmegaConf
OmegaConf.register_new_resolver("plus_10", lambda x: x + 10)
OmegaConf.register_new_resolver("random_number", lambda: random.randint(0, 1000))
c = OmegaConf.create(
{
"key": "${plus_10:990}",
"key2": "${random_number}",
}
)
print(c.key, c.key2)
Output:
...
omegaconf.errors.InterpolationKeyError: Interpolation key 'random_number' not found
full_key: key2
object_type=dict
Interestingly, adding :
with or without any dummy parameter seems to work, but it's not very idiomatic:
import random
from omegaconf import OmegaConf
OmegaConf.register_new_resolver("plus_10", lambda x: x + 10)
OmegaConf.register_new_resolver("random_number", lambda: random.randint(0, 1000))
c = OmegaConf.create(
{
"key": "${plus_10:990}",
"key2": "${random_number:}",
}
)
print(c.key, c.key2)
Any thoughts?
5.13.0-41-generic #46~20.04.1-Ubuntu SMP Wed Apr 20 13:16:21 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Allow for creating resolvers that take no arguments. E.g.,
OmegaConf.register_new_resolver("cpus", lambda : os.cpu_count)
Currently attempts at this throws an exception.