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`.
This commit is contained in:
Jason Robinson 2020-12-15 00:27:58 +02:00 committed by GitHub
parent 6b0c82ccde
commit ff008a6aac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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