python-configuration icon indicating copy to clipboard operation
python-configuration copied to clipboard

Dot-based keys don't interpolate

Open chinghwayu opened this issue 4 years ago • 3 comments

values_1 = {"a.b": "value"}
values_2 = {"var": "{a.b}"}

cfg = config(
    values_2,
    values_1,
    lowercase_keys=True,
    interpolate=True,
)
print(cfg.var)

Results in:

  File "/group/siv_roast_bkup/staff/chinghwa/python-configuration/config/configuration_set.py", line 113, in __getattr__
    return self._from_configs("__getattr__", item)
  File "/group/siv_roast_bkup/staff/chinghwa/python-configuration/config/configuration_set.py", line 83, in _from_configs
    return interpolate_object(args[0], values[0], d, self._interpolate_type)
  File "/group/siv_roast_bkup/staff/chinghwa/python-configuration/config/helpers.py", line 192, in interpolate_object
    return interpolate_standard(obj, flatten(d), set())
  File "/group/siv_roast_bkup/staff/chinghwa/python-configuration/config/helpers.py", line 112, in interpolate_standard
    return text.format(**interpolated)
KeyError: 'a'

chinghwayu avatar Aug 05 '20 01:08 chinghwayu

Can you test PR #37?

tr11 avatar Aug 05 '20 03:08 tr11

conf.py:

my__var = "hello"

dir/conf.py

var = {my.var}

loader:

module_list = ["dir/conf.py","conf.py"]
cfg = config(*module_list, separator="__", interpolate=True, interpolate_type=InterpolateEnumType.DEEP)

cfg["var"] will only work when interpolate_type is STANDARD

chinghwayu avatar Aug 05 '20 23:08 chinghwayu

Yeah, I noticed that this morning when I realized I only changed one of the methods. I'll take a look at it this weekend

tr11 avatar Aug 05 '20 23:08 tr11