# HG changeset patch # User Franz Glasner # Date 1638396540 -3600 # Node ID 2abde0d3c735150b5e183bbc038b651aadb04b09 # Parent 606feee43e71ade468a518b9ff3f609d2d205687 FIX: Handle .jailed() with an empty "root" properly diff -r 606feee43e71 -r 2abde0d3c735 configmix/config.py --- a/configmix/config.py Mon Nov 22 09:34:16 2021 +0100 +++ b/configmix/config.py Wed Dec 01 23:09:00 2021 +0100 @@ -689,16 +689,21 @@ raise ValueError("only one of `rootpath' or `root' can be given") if rootpath is None and root is None: raise ValueError("one of `rootpath' or `root' must be given") + if rootpath is not None and not isinstance(rootpath, (list, tuple)): + raise TypeError("`rootpath' must be a list or a tuple") if root is not None: # convert to path varns, varname = self._split_ns(root) if varns: raise ValueError( "jailed configurations do not support namespaces") - rootpath = [ - self.unquote(p) for p in root.split( - self._HIER_SEPARATOR) - ] + if varname: + rootpath = [ + self.unquote(p) for p in root.split( + self._HIER_SEPARATOR) + ] + else: + rootpath = tuple() jc = _JailedConfiguration(*rootpath) if bind_root: jc.rebind(self) diff -r 606feee43e71 -r 2abde0d3c735 tests/test.py --- a/tests/test.py Mon Nov 22 09:34:16 2021 +0100 +++ b/tests/test.py Wed Dec 01 23:09:00 2021 +0100 @@ -1241,7 +1241,7 @@ def test_root_empty(self): cfg = configmix.load(os.path.join(TESTDATADIR, "conf10.py")) - jcfg = cfg.jailed(rootpath=u"") + jcfg = cfg.jailed(root=u"") self.assertTrue(jcfg.getvarl(u"tree1", u"tree2", u"key5")) self.assertTrue(jcfg.getvarl_s(u"tree1", u"tree2", u"key5"))