Subject: [PATCH 1 of 2 py-scfg] Return None when trying to get missing sub-directive

From: David Keijser <[email-masked]>
Date: Sun, 01 Nov 2020 17:51:12 +0100

# HG changeset patch
# User David Keijser <[email-masked]>
# 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()

---

From: Peter Sanchez <[email-masked]>
Date: Sun, 1 Nov 2020 15:44:01 -0800

>Return None when trying to get missing sub-directive

Thanks! It's been applied and submitted a new version to pypi.

Just a heads up, the proper mailing list for this repo is:

~petersanchez/[email-masked]

No big deal just don't want to accidentally miss your submissions as I
usually ignore this list (it's for testing).

---

From: David Keijser <[email-masked]>
Date: Mon, 2 Nov 2020 11:22:07 +0100

> Thanks! It's been applied and submitted a new version to pypi.

Ok, cool. Did the other patch make it to you too?

Having type annotations would be great when writing code using scfg
because it enables type checking with mypy and nice editor integration
with langserver and the like.

> usually ignore this list (it's for testing).

Oof, that's what I get for pasting the first code block I see into
config files.