Commit 64df2de1 authored by Tim Schoof's avatar Tim Schoof
Browse files

Fix configuration with values considered as False

parent 7c5741f0
Pipeline #14412 passed with stage
in 49 seconds
......@@ -155,6 +155,13 @@ def create_cli_parser_for_attribute(attribute, parser, prefix, short_prefix):
def create_instance_from_configurable(
type, options, kwargs=None, builder=None):
Create an instance of type using the given options.
The kwargs argument can be used to overwrite options.
If no builder is given the constructor of type will be used.
if kwargs is None:
kwargs = {}
if builder is None:
......@@ -165,11 +172,25 @@ def create_instance_from_configurable(
def create_instance_from_attribute(attribute, options, kwargs):
Insert a value for the attribute into kwargs using the values given in
If the attribute has a complex type, the value will be an instance
that is constructed from the given options.
Does nothing if kwargs already has an entry for the attribute name.
if in kwargs:
config_entry = attribute.metadata[CONFIGURABLE_CONFIG_ENTRY]
if not config_entry.flatten:
options = options.get(, {})
if options is not attr.NOTHING:
options = options.get(, attr.NOTHING)
# else default options for this attribute will be used
# flatten only works for attributes that have complex types
assert config_entry.proxy is not None or attr.has(attribute.type)
if config_entry.proxy is not None:
proxy_instance = create_instance_from_configurable(
config_entry.proxy, options)
......@@ -179,8 +200,12 @@ def create_instance_from_attribute(attribute, options, kwargs):
kwargs[] = create_instance_from_configurable(
attribute.type, options, builder=config_entry.builder)
if options:
# attribute has a simple type
assert not config_entry.flatten
if options is not attr.NOTHING:
# use given option for this attribute
kwargs[] = options
# else default options for this attribute will be used
def parsed_args_to_dict(parsed):
......@@ -473,3 +473,13 @@ def test_create_instance_overwrite_options_via_kwargs():
assert instance.simple_attribute is simple_attribute
assert instance.configurable_attribute is configurable_attribute
assert instance.extern_attribute is extern_attribute
def test_create_instance_from_configurable_zero():
class Foo:
i = Config("An integer", type=int, default=1)
instance = create_instance_from_configurable(Foo, {"i": 0})
assert instance.i == 0
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment