fix: add dependency for calculation in choice values
This commit is contained in:
parent
ebc9779173
commit
ac35f2428b
2 changed files with 11 additions and 2 deletions
|
|
@ -162,6 +162,10 @@ def test_choiceoption_calc_opt_function(config_type):
|
||||||
cfg = get_config(cfg, config_type)
|
cfg = get_config(cfg, config_type)
|
||||||
assert cfg.option('choice').owner.isdefault()
|
assert cfg.option('choice').owner.isdefault()
|
||||||
#
|
#
|
||||||
|
dep = cfg.option('str').dependencies()
|
||||||
|
assert len(dep) == 1
|
||||||
|
assert dep[0].path() == 'choice'
|
||||||
|
#
|
||||||
cfg.option('choice').value.set('val1')
|
cfg.option('choice').value.set('val1')
|
||||||
assert cfg.option('choice').owner.get() == owner
|
assert cfg.option('choice').owner.get() == owner
|
||||||
#
|
#
|
||||||
|
|
|
||||||
|
|
@ -21,11 +21,12 @@
|
||||||
"""ChoiceOption
|
"""ChoiceOption
|
||||||
"""
|
"""
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
from itertools import chain
|
||||||
|
|
||||||
from ..setting import undefined
|
from ..setting import undefined
|
||||||
from ..i18n import _
|
from ..i18n import _
|
||||||
from .option import Option
|
from .option import Option
|
||||||
from ..autolib import Calculation, get_calculated_value
|
from ..autolib import Calculation, get_calculated_value, ParamOption
|
||||||
from ..error import ConfigError, display_list
|
from ..error import ConfigError, display_list
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -42,7 +43,11 @@ class ChoiceOption(Option):
|
||||||
"""
|
"""
|
||||||
:param values: is a list of values the option can possibly take
|
:param values: is a list of values the option can possibly take
|
||||||
"""
|
"""
|
||||||
if not isinstance(values, (Calculation, tuple)):
|
if isinstance(values, Calculation):
|
||||||
|
for param in chain(values.params.args, values.params.kwargs.values()):
|
||||||
|
if isinstance(param, ParamOption):
|
||||||
|
param.option._add_dependency(self)
|
||||||
|
elif not isinstance(values, tuple):
|
||||||
raise TypeError(
|
raise TypeError(
|
||||||
_("values must be a tuple or a calculation for {0}").format(name)
|
_("values must be a tuple or a calculation for {0}").format(name)
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue