simplify set with undefined

This commit is contained in:
Emmanuel Garette 2018-09-29 08:27:00 +02:00
parent 242615f68b
commit 996a6c7303
2 changed files with 19 additions and 34 deletions

View File

@ -427,15 +427,10 @@ class TiramisuOptionValue(CommonTiramisuOption):
if isinstance(value, list):
while undefined in value:
idx = value.index(undefined)
option_bag = OptionBag()
option_bag.set_option(self.option_bag.option,
self.option_bag.path,
idx,
self.option_bag.config_bag)
value[idx] = values.getdefaultvalue(option_bag)
else:
if value == undefined:
value = values.getdefaultvalue(self.option_bag)
value[idx] = values.getdefaultvalue(self.option_bag,
force_index=idx)
elif value == undefined:
value = values.getdefaultvalue(self.option_bag)
self.subconfig.setattr(value,
self.option_bag)
@ -956,9 +951,8 @@ class TiramisuContextOption(TiramisuContext):
if type == 'option' or (type == 'optiondescription' and \
group_type and opt.impl_get_group_type() != group_type):
continue
else:
if type == 'optiondescription':
continue
elif type == 'optiondescription':
continue
path = opt.impl_getpath()
subconfig, name = self.config_bag.context.cfgimpl_get_home_by_path(path,
self.config_bag)

View File

@ -16,6 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# ____________________________________________________________
import weakref
from typing import Optional
from .error import ConfigError, PropertiesOptionError
from .setting import owners, expires_time, undefined, forbidden_owners, OptionBag, ConfigBag
from .autolib import carry_out_calculation
@ -124,7 +125,8 @@ class Values(object):
return self.getdefaultvalue(option_bag)
def getdefaultvalue(self,
option_bag):
option_bag,
force_index: Optional[int]=None):
"""get default value:
- get meta config value or
- get calculated value or
@ -140,6 +142,8 @@ class Values(object):
context = config_bag.context
opt = option_bag.option
index = option_bag.index
if force_index is not None:
index = force_index
def _reset_cache(_value):
if not 'expire' in option_bag.properties:
return
@ -156,24 +160,11 @@ class Values(object):
# calculated value is a new value, so reset cache
context.cfgimpl_reset_cache(option_bag)
if opt.impl_is_master_slaves('slave'):
index_ = index
else:
index_ = None
if option_bag.index != index_:
moption_bag = OptionBag()
moption_bag.set_option(opt,
option_bag.path,
index_,
config_bag)
moption_bag.fromconsistency = option_bag.fromconsistency.copy()
else:
moption_bag = option_bag
if self._is_meta(moption_bag):
moption_bag.properties = frozenset()
if self._is_meta(option_bag):
option_bag.properties = frozenset()
meta = context.cfgimpl_get_meta()
# retrieved value from meta config
return meta.cfgimpl_get_values().get_cached_value(moption_bag)
return meta.cfgimpl_get_values().get_cached_value(option_bag)
if opt.impl_has_callback():
# if value has callback, calculate value
@ -390,13 +381,13 @@ class Values(object):
owners.default,
index=option_bag.index)
if owner is owners.default and validate_meta is not False and self._is_meta(option_bag):
moption_bag = option_bag.copy()
moption_bag.properties = frozenset()
config_bag = moption_bag.config_bag.copy()
option_bag = option_bag.copy()
option_bag.properties = frozenset()
config_bag = option_bag.config_bag.copy()
meta = context.cfgimpl_get_meta()
config_bag.context = meta
moption_bag.config_bag = config_bag
owner = meta.cfgimpl_get_values().getowner(moption_bag,
option_bag.config_bag = config_bag
owner = meta.cfgimpl_get_values().getowner(option_bag,
only_default=only_default)
return owner