From 99bf042ea5977456b39e00c235902c42af91196b Mon Sep 17 00:00:00 2001 From: Ulf Magnusson Date: Thu, 6 Dec 2012 21:16:22 +0100 Subject: Clarify and tighten up get_assignable_values(). Also get rid of the kludgey _is_assignable_bool_or_tristate(). --- kconfiglib.py | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) (limited to 'kconfiglib.py') diff --git a/kconfiglib.py b/kconfiglib.py index fa3d7e1..fa51ae2 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -2511,20 +2511,27 @@ class Symbol(Item, _HasVisibility): return None def get_assignable_values(self): - """For bool and tristate symbols, returns a list containing the values - the symbol can be given via Symbol.set_value() (see get_lower_bound()/ - get_upper_bound()). Returns the empty list for symbol that cannot be - given a new value (that cannot be assigned a value that won't be - truncated/ignored that is), as well as for non-bool, non-tristate and - special symbols. Usage example: + """For string/hex/int symbols and for bool and tristate symbols that + cannot be modified (see is_modifiable()), returns the empty list. + + Otherwise, returns a list containing the tristate values that can be + assigned to the symbol (that won't be truncated). Usage example: if "m" in sym.get_assignable_values(): - sym.set_value("m")""" - if not self._is_assignable_bool_or_tristate(): - return [] + sym.set_value("m") - return ["n", "m", "y"][values[self.config._eval_expr(self.rev_dep)] : - values[self._calc_visibility()] + 1] + This is basically a more convenient interface to + get_lower/upper_bound() when wanting to test if a particular tristate + value can be assigned.""" + if self.type not in (BOOL, TRISTATE): + return [] + rev_dep = self.config._eval_expr(self.rev_dep) + # A bool selected to "m" gets promoted to "y" + if self.type == BOOL and rev_dep == "m": + rev_dep = "y" + res = ["n", "m", "y"][self.config._eval_to_int(rev_dep) : + self.config._eval_to_int(self._calc_visibility()) + 1] + return res if len(res) > 1 else [] def get_type(self): """Returns the type of the symbol: one of UNKNOWN, BOOL, TRISTATE, @@ -2966,14 +2973,6 @@ class Symbol(Item, _HasVisibility): return False - def _is_assignable_bool_or_tristate(self): - """Returns True if the symbol is a bool or tristate whose value can be - changed by the user.""" - return self.type in (BOOL, TRISTATE) and \ - not self.is_special_ and \ - (self.config._eval_to_int(self._calc_visibility()) - - self.config._eval_to_int(self.config._eval_expr(self.rev_dep))) >= 1 - class Menu(Item): """Represents a menu statement.""" -- cgit v1.2.3