From ff008a6aac141cbbebf89551cb95674bb0af87c0 Mon Sep 17 00:00:00 2001 From: Jason Robinson Date: Tue, 15 Dec 2020 00:27:58 +0200 Subject: [PATCH] Allow config items to really be required=False (#20) In the case of `required or not default` with default defaulting to `None` it's impossible to have a `required=False` config item, without supplying a default To make `required=False` actually mean "you don't need to specify this at all", it needs to be `required and not default` when checking if we should raise `ConfigError`. --- my_project_name/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/my_project_name/config.py b/my_project_name/config.py index 863204a..c7d44a0 100644 --- a/my_project_name/config.py +++ b/my_project_name/config.py @@ -112,7 +112,7 @@ class Config(object): # If at any point we don't get our expected option... if config is None: # Raise an error if it was required - if required or not default: + if required and not default: raise ConfigError(f"Config option {'.'.join(path)} is required") # or return the default value