Giter Site home page Giter Site logo

Comments (3)

aalba6675 avatar aalba6675 commented on August 19, 2024

The merge_configs() method is merging the top config into the base confiig and returning the latter.

RFC: for #95 and #105: how about using deepcopy in with_fallback? Smoke testing the gist above and #95 are working.

I'll leave this comment for a while before a PR.

import copy
#### way down 
    def with_fallback(self, config):
        """
        return a new config with fallback on config
        :param config: config or filename of the config to fallback on
        :return: new config with fallback on config
        """
        if isinstance(config, ConfigTree):
            config = copy.deepcopy(config)
            result = ConfigTree.merge_configs(config, copy.deepcopy(self))
        else:
            from . import ConfigFactory
            result = ConfigTree.merge_configs(ConfigFactory.parse_file(config, resolve=False), copy.deepcopy(self))

        from . import ConfigParser
        ConfigParser.resolve_substitutions(result)
        return result

from pyhocon.

aalba6675 avatar aalba6675 commented on August 19, 2024

Smoketest #105:

>>> from pyhocon.config_tree import ConfigTree as CT
>>> config_tree = CT()
>>> 
>>> config_tree.put("a.b.c", value1)
>>> assert config_tree.get("a.b.c") == value1
>>> 
>>> config_tree.put("a.b.c", value2)
>>> assert config_tree.get("a.b.c") == value2
>>> 
>>> config_tree.put("a.b.c", value3, True)
>>> assert config_tree.get("a.b.c") == (value2 + value3)
>>> 

from pyhocon.

aalba6675 avatar aalba6675 commented on August 19, 2024

Return a new object; don't mutate object and argument in config2.with_fallback(config1)

Smoketest #95:

>>> 
>>> from pyhocon.config_parser import ConfigParser as CP, ConfigFactory as CF
>>> 
>>> config1 = CF.parse_string('''
...     string = abc
... ''')
>>> 
>>> config2 = CF.parse_string('''
...     string = ${string}def
... ''', resolve=False)
>>> 
>>> ret = config2.with_fallback(config1)
>>> ret
ConfigTree([('string', 'abcdef')])
>>> config1
ConfigTree([('string', 'abc')])
>>> config2
ConfigTree([('string', [ConfigValues: [ConfigSubstitution: string],def])])
>>> 
>>> ret is config2
False
>>> ret is config1
False
>>> 

from pyhocon.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.