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.
# 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
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/public-inbox@lists.code.netlandish.com
No big deal just don't want to accidentally miss your submissions as I
usually ignore this list (it's for testing).
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()