~netlandish/email-test-drive

1 of 2 py-scfg: Return None when trying to get missing sub-directive v1 APPLIED

David Keijser: 1
 Return None when trying to get missing sub-directive

 2 files changed, 10 insertions(+), 2 deletions(-)
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.
Next
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.code.netlandish.com/~netlandish/email-test-drive/patches/3/mbox | git am -3
Learn more about email & git

[PATCH 1 of 2 py-scfg] Return None when trying to get missing sub-directive Export this patch

# HG changeset patch
# User David Keijser <keijser@gmail.com>
# 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()