# HG changeset patch # User David Keijser # Date 1604248014 -3600 # Sun Nov 01 17:26:54 2020 +0100 # Node ID 33f5a3354dc7b1fce8639602d4212da01c7da19a # Parent 64f694b06df5c2f5140d456de6304804d4d8c8be Return None when trying to get missing sub-directive This aligns with the behaviour of get on the top-level directive, previously it would instead raise an exception. diff --git a/scfg/__init__.py b/scfg/__init__.py --- a/scfg/__init__.py +++ b/scfg/__init__.py @@ -23,8 +23,7 @@ def __init__(self, name, params, children=None): self.name = name self.params = params - if children is not None: - self.children = children + self.children = children or [] def __str__(self): return f"{self.name}: {self.params}" diff --git a/tests.py b/tests.py --- a/tests.py +++ b/tests.py @@ -26,6 +26,15 @@ train.get_all("model")[1].get("weight").params[0], "540t" ) + def test_access_missing(self): + train = self.config.get("train") + self.assertEqual( + train.get("missing"), None + ) + self.assertEqual( + train.get_all("model")[0].get("lines-served").get("missing"), None + ) + if __name__ == "__main__": unittest.main()