Skip to content

Commit

Permalink
Fix handling of config_default in store_true (#31)
Browse files Browse the repository at this point in the history
config_default was not being used in store_true when no default is
specified. Fix that.

Add the tests using config_default=SUPPRESS that caught this.
  • Loading branch information
jonathanhaigh authored Jun 4, 2020
1 parent d9c1e0e commit 539f2e2
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 108 deletions.
39 changes: 13 additions & 26 deletions multiconfig/multiconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,11 +560,8 @@ def _accumulate_processed_value(self, current, new):
return new

def apply_default(self, value, global_default):
default = self.default
if default is NONE:
default = global_default
if value is NONE:
return default
return self.default
if self.nargs == ZERO_OR_ONE and value is PRESENT_WITHOUT_VALUE:
return self.const
return value
Expand Down Expand Up @@ -605,13 +602,10 @@ def _accumulate_processed_value(self, current, new):
return PRESENT_WITHOUT_VALUE

def apply_default(self, value, global_default):
default = self.default
if default is NONE:
default = global_default
if value is PRESENT_WITHOUT_VALUE:
return self.const
assert value is NONE
return default
return self.default


class _StoreTrueConfigSpec(_StoreConstConfigSpec):
Expand Down Expand Up @@ -652,18 +646,15 @@ def _accumulate_processed_value(self, current, new):
return current + [new]

def apply_default(self, value, global_default):
default = self.default
if default is NONE:
default = global_default
if value is NONE:
return default
return self.default
if self.nargs == ZERO_OR_ONE:
const = None
if self.const is not NONE:
const = self.const
value = [const if v is PRESENT_WITHOUT_VALUE else v for v in value]
if default is not NONE and default is not SUPPRESS:
return default + value
if self.default is not NONE and self.default is not SUPPRESS:
return self.default + value
return value

def _set_nargs(self, nargs):
Expand Down Expand Up @@ -701,13 +692,10 @@ def _accumulate_processed_value(self, current, new):
return current + 1

def apply_default(self, value, global_default):
default = self.default
if default is NONE:
default = global_default
if value is NONE:
return default
if default is not NONE and default is not SUPPRESS:
return default + value
return self.default
if self.default is not NONE and self.default is not SUPPRESS:
return self.default + value
return value


Expand All @@ -729,13 +717,10 @@ def _accumulate_processed_value(self, current, new):
return current + new

def apply_default(self, value, global_default):
default = self.default
if default is NONE:
default = global_default
if value is NONE:
return default
if default is not NONE and default is not SUPPRESS:
return default + value
return self.default
if self.default is not NONE and self.default is not SUPPRESS:
return self.default + value
return value


Expand All @@ -761,6 +746,8 @@ def add_config(self, name, **kwargs):
"""
Add a config item to this ConfigParser.
"""
if "default" not in kwargs and self._global_default is not NONE:
kwargs["default"] = self._global_default
spec = _ConfigSpec.create(name=name, **kwargs)
self._config_specs.append(spec)
return spec
Expand Down
Loading

0 comments on commit 539f2e2

Please sign in to comment.