From d938d82ef9bfb3eb4e015ecdb678c4a185627682 Mon Sep 17 00:00:00 2001 From: Victor Lin <13424970+victorlin@users.noreply.github.com> Date: Thu, 14 Sep 2023 11:41:37 -0700 Subject: [PATCH] Add another way of accessing config values Checking presence of a key in the config should be done with the membership operator. This must be done otherwise false-y values will stay false when membership is checked with config.get. --- src/reference/snakemake-style-guide.rst | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/reference/snakemake-style-guide.rst b/src/reference/snakemake-style-guide.rst index dc2825d2..dc8f234f 100644 --- a/src/reference/snakemake-style-guide.rst +++ b/src/reference/snakemake-style-guide.rst @@ -82,11 +82,15 @@ global variable. 3 ways are supported, but only 2 should be used: 1. ``config[key]``: Use this when the key is required, or a default is specified in a pre-loaded configuration file. -2. ``config.get(key, default)``: Use this when the key is optional. +2. ``key [not] in config``: Use this when the key is optional and you + want to check if a value is specified. -3. ``config.get(key)``: Never use this. All use cases should be covered - by (1) and (2). Using this will only mask errors that may be due to a - missing required key. +3. ``config.get(key, default)``: Use this when the key is optional and + you want to access its value. + +4. ``config.get(key)``: **Never use this**. All use cases should be covered + by the options above. Using this will only mask errors that may be + due to a missing required key. Use Snakemake ``params:`` block to map into ``config`` dictionary =================================================================