changeset 742:220a9ec9ac72

- Docs the the new list merging strategies. Also some more words about merging generally. - One more test about the default of "replacing" lists.
author Franz Glasner <fzglas.hg@dom66.de>
date Sun, 29 Oct 2023 17:29:16 +0100
parents e069797f0e36
children b26a1afe0558
files docs/introduction.rst tests/test.py
diffstat 2 files changed, 17 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/docs/introduction.rst	Sun Oct 29 17:15:41 2023 +0100
+++ b/docs/introduction.rst	Sun Oct 29 17:29:16 2023 +0100
@@ -195,6 +195,17 @@
   ``.yml`` or ``.yaml``
     for YAML configuration files
 
+When loading two or more configuration files the configurations will be
+merged:
+
+* later values overwrite earlier values
+* :py:class:`dict`-like objects are merged `recursively`
+* :py:class:`list` objects are by default completely replaced by later ones.
+  When using ``merge_lists="extend"`` then later list extend earlier lists,
+  when using ``merge_lists="prepend"`` then earlier lists extend later ones.
+
+  This is done `non-recursively`.
+
 
 .. _getting-values:
 
--- a/tests/test.py	Sun Oct 29 17:15:41 2023 +0100
+++ b/tests/test.py	Sun Oct 29 17:29:16 2023 +0100
@@ -1041,6 +1041,12 @@
                           u"val1", u"val2", u"in the root namespace",],
                          cfg.getvarl_s(u"tree1", u"tree2", u"key8"))
 
+    def test59_list_merge_default(self):
+        cfg = self._load(os.path.join(TESTDATADIR, "conf10.toml"),
+                         os.path.join(TESTDATADIR, "conf10_list_extend.yml"))
+        self.assertEqual([u"val4", u"val5", u"val6",],
+                         cfg.getvarl_s(u"tree1", u"tree2", u"key8"))
+
 
 class T02LoadAndMerge(_T02MixinLoadAndMerge, unittest.TestCase):