Skip to content

Feature: Add interpolate keyword to as_dict() and as_attrdict() #33

Open

Description

@chinghwayu
from config import config
DICT = {"var": "1", "var1": "{var}"}
cfg = config(DICT, interpolate=True)
print(cfg.as_dict())
print(cfg.as_attrdict())

Results is:

{'var': '1', 'var1': '{var}'}
{'var': '1', 'var1': '{var}'}

Activity

  1. tr11 commented on Jul 13, 2020

    @tr11
    Owner

    That's by design -- maybe I can add an interpolate keyword to both methods to perform the interpolations.

  2. changed the title [-]as.dict() and as.attrdict() do not interpolate when interpolate=True[/-] [+]Feature: Add interpolate keyword to as_dict() and as_attrdict()[/+] on Jul 13, 2020
  3. tr11 commented on Aug 1, 2020

    @tr11
    Owner

    Take a look at #35. Can you test it to see if it does what you need?

  4. chinghwayu commented on Aug 4, 2020

    @chinghwayu
    ContributorAuthor

    I'm getting an error with
    conf.py

    var = "hello"
    

    dir/conf.py

    var2 = "{var}/else"
    var3 = ["{var}", "{var2}"]
    
    A__B = "{var}"
    

    mytest.py

    module_list = ["dir/conf.py","conf.py"]
    cfg = config(*module_list, separator="__", interpolate=True, interpolate_type=InterpolateEnumType.DEEP_NO_BACKTRACK)
    print(cfg.as_attrdict(interpolation=True))
    
      File "/group/siv_roast_bkup/staff/chinghwa/config-test/mytest.py", line 14, in <module>
        print(cfg.as_attrdict(interpolation=True))
      File "/group/siv_roast_bkup/staff/chinghwa/python-configuration/config/configuration.py", line 202, in as_attrdict
        d = self.as_dict(interpolation=interpolation, nested=nested)
      File "/group/siv_roast_bkup/staff/chinghwa/python-configuration/config/configuration_set.py", line 133, in as_dict
        return Configuration(result).as_dict(interpolation=interpolation, nested=nested)
      File "/group/siv_roast_bkup/staff/chinghwa/python-configuration/config/configuration.py", line 184, in as_dict
        v = v.as_dict(interpolation=True)
      File "/group/siv_roast_bkup/staff/chinghwa/python-configuration/config/configuration.py", line 184, in as_dict
        v = v.as_dict(interpolation=True)
      File "/group/siv_roast_bkup/staff/chinghwa/python-configuration/config/configuration.py", line 184, in as_dict
        v = v.as_dict(interpolation=True)
      File "/group/siv_roast_bkup/staff/chinghwa/python-configuration/config/configuration.py", line 182, in as_dict
        v = interpolated_copy[cast(str, k)]
      File "/group/siv_roast_bkup/staff/chinghwa/python-configuration/config/configuration.py", line 157, in __getitem__
        return interpolate_object(item, v, [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 111, in interpolate_standard
        interpolated = {v: interpolate_standard(d[v], d, found) for v in variables}
      File "/group/siv_roast_bkup/staff/chinghwa/python-configuration/config/helpers.py", line 111, in <dictcomp>
        interpolated = {v: interpolate_standard(d[v], d, found) for v in variables}
    KeyError: 'var'
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions