Received: from mail.netlandish.com (unknown [10.138.202.29]) by code.netlandish.com (Postfix) with ESMTP id 3498480B83 for <~netlandish/email-test-drive@lists.code.netlandish.com>; Sun, 1 Nov 2020 16:51:21 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=209.85.218.50; helo=mail-ej1-f50.google.com; envelope-from=keijser@gmail.com; receiver= Authentication-Results: mail.netlandish.com; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=DJBUZX6I Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) by mail.netlandish.com (Postfix) with ESMTP id 2CDF583729 for <~netlandish/email-test-drive@lists.code.netlandish.com>; Sun, 1 Nov 2020 08:51:19 -0800 (PST) Received: by mail-ej1-f50.google.com with SMTP id k3so15287523ejj.10 for <~netlandish/email-test-drive@lists.code.netlandish.com>; Sun, 01 Nov 2020 08:51:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:content-transfer-encoding:subject:message-id :user-agent:date:from:to; bh=1B8t8Q5nmosWsaGQ/JJb7WVCy702Ro9seTJDsfnq/m4=; b=DJBUZX6IBYj2Xk+PYD0S+mwdKGrd+yZG7vTvxGupoRySr5i6oN7iudx/lPHkh9M5Ne cZK8+2Nx84ETfVBWtseoObZSo75zc+SBokheE8ZE1PPkRO/+2tpajHNG6zKWfSPIi7Ku Jxbu+HRNX7R3aoQewOA2SKeWwWFSeg1Ft58hCwHBX0xnRPFU8FRWrPPYAmpLti9x8Zel 0nDtXW4WrWM3hAQ+R2EPF161OirQyFSPCfAgC7vMP8x0HJ7Zl5783EmKnDFj2i0ZRqGJ GNvvfCqrG2fBqzA8mcuQj+Px2EnEyWrLHouiH9x2AZWgi8LLvyu13vJr6Z8OHh3us38o dzfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:content-transfer-encoding:subject :message-id:user-agent:date:from:to; bh=1B8t8Q5nmosWsaGQ/JJb7WVCy702Ro9seTJDsfnq/m4=; b=R4fCSEzAzhYzPd/X/FjJ+/8ZLEMpki1q8aL9drNCu+PaSep//oeY0s24d6VBe8OjdC En7/1zV2MdiTklKd2a7C5L0lvSFfMGcS3+PsDV96BCGd4LU47e2BVrCXr8OMCUU2NXie Q6lHjIIabwRU5l2EXQP8vGZHmJ2u03N5IFotZLpS4Ts9CS5WBU+mI7pPSlzHIU9ZifPX E5zxDSK44c4R0OJ2EKoeem58SxFHE6/v3yuIeu64B8xfkczbhmDPdL+0wDPhXRtlkr7v gAzjvEFjaEy+OQ7Hj4o6Ygc7igpWJnFsIi8qJlUEp1bemAWt2SbWNqLZFR0RVXV5g1/i IDRg== X-Gm-Message-State: AOAM531OWwaMGZKkpGRclub4Z0AJroFXHBV6f3mVY7YGNg2FNrB4P+ug be13KlMaxF1azU5UBCfQ40kr7koVRb8= X-Google-Smtp-Source: ABdhPJzsx4vCEnfD1SdPKPF46QKYb5pjDWHg5nn5OYDYpJ7gawJUS7PzM3UE0chdI5x3+irPvk2qxA== X-Received: by 2002:a17:906:c094:: with SMTP id f20mr12138783ejz.550.1604249478528; Sun, 01 Nov 2020 08:51:18 -0800 (PST) Received: from localhost ([91.141.210.63]) by smtp.gmail.com with ESMTPSA id yw17sm7779565ejb.97.2020.11.01.08.51.17 for <~netlandish/email-test-drive@lists.code.netlandish.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Nov 2020 08:51:18 -0800 (PST) MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Subject: [PATCH 1 of 2 py-scfg] Return None when trying to get missing sub-directive X-Mercurial-Node: 33f5a3354dc7b1fce8639602d4212da01c7da19a X-Mercurial-Series-Index: 1 X-Mercurial-Series-Total: 2 Message-Id: <33f5a3354dc7b1fce863.1604249472@splurge.local> X-Mercurial-Series-Id: <33f5a3354dc7b1fce863.1604249472@splurge.local> User-Agent: Mercurial-patchbomb/5.4 Date: Sun, 01 Nov 2020 17:51:12 +0100 From: David Keijser To: ~netlandish/email-test-drive@lists.code.netlandish.com # 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()