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

Interpolation error with DEEP or DEEP_NO_BACKTRACK

Open chinghwayu opened this issue 4 years ago • 2 comments

conf.py

var1 = "2020"
var2 = "{var1}"
var3 = "{var1}/{var2}"

mytest.py

module_list = ["conf.py"]
cfg = config(*module_list, separator="__", interpolate=True, interpolate_type=InterpolateEnumType.DEEP_NO_BACKTRACK)
print(cfg["var3"])

Sometimes it will work and return

2020/2020

But other times, it will return

  File "/home/chinghwa/.pyenv/versions/py365-dev/lib/python3.6/site-packages/config/configuration_set.py", line 110, in __getitem__
    return self._from_configs("__getitem__", item)
  File "/home/chinghwa/.pyenv/versions/py365-dev/lib/python3.6/site-packages/config/configuration_set.py", line 83, in _from_configs
    return interpolate_object(args[0], values[0], d, self._interpolate_type)
  File "/home/chinghwa/.pyenv/versions/py365-dev/lib/python3.6/site-packages/config/helpers.py", line 197, in interpolate_object
    return interpolate_deep(attr, obj, d, {}, {}, method)
  File "/home/chinghwa/.pyenv/versions/py365-dev/lib/python3.6/site-packages/config/helpers.py", line 147, in interpolate_deep
    raise KeyError(variable)
KeyError: 'var1'

chinghwayu avatar Sep 29 '20 23:09 chinghwayu

I'll take a look at it this weekend. I'm planning on unifying the way the templating works that will hopefully fix all these issues

tr11 avatar Sep 30 '20 18:09 tr11

I'll take a look at it this weekend. I'm planning on unifying the way the templating works that will hopefully fix all these issues

Any chance at looking at this again in the near future? 😀

chinghwayu avatar Nov 11 '20 22:11 chinghwayu