diff options
| author | Ulf Magnusson <ulfalizer@gmail.com> | 2019-06-21 01:07:37 +0200 |
|---|---|---|
| committer | Ulf Magnusson <ulfalizer@gmail.com> | 2019-06-21 01:47:02 +0200 |
| commit | f2ac5e3c03c34d13b818ba64441fd6511d8f75a4 (patch) | |
| tree | 75232ae84cf5cbed561c71083b38efdb1f2e21b9 | |
| parent | 823f6952a18c200fccfbd5e54c32c78289ed8570 (diff) | |
Make set_value() no-change check work for "n"/"m"/"y" strings
Convert "n"/"m"/"y" to 0/1/2 earlier, so that e.g. sym.set_value("y")
is recognized as a no-op when sym.user_value == 2.
This also helps when loading several configuration files that assign
some of the same symbols, because load_config() calls set_value() with
"n"/"m"/"y".
This could also cut down on the number of times a particular warning is
displayed when loading lots of overlapping configuration files.
| -rw-r--r-- | kconfiglib.py | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/kconfiglib.py b/kconfiglib.py index 7752f21..4d26cdd 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -4450,6 +4450,9 @@ class Symbol(object): value of the symbol. For other symbol types, check whether the visibility is non-n. """ + if self.orig_type in _BOOL_TRISTATE and value in STR_TO_TRI: + value = STR_TO_TRI[value] + # If the new user value matches the old, nothing changes, and we can # save some work. # @@ -4462,11 +4465,11 @@ class Symbol(object): return True # Check if the value is valid for our type - if not (self.orig_type is BOOL and value in (2, 0, "y", "n") or - self.orig_type is TRISTATE and value in (2, 1, 0, "y", "m", "n") or + if not (self.orig_type is BOOL and value in (2, 0) or + self.orig_type is TRISTATE and value in TRI_TO_STR or (value.__class__ is str and - (self.orig_type is STRING or - self.orig_type is INT and _is_base_n(value, 10) or + (self.orig_type is STRING or + self.orig_type is INT and _is_base_n(value, 10) or self.orig_type is HEX and _is_base_n(value, 16) and int(value, 16) >= 0))): @@ -4474,15 +4477,12 @@ class Symbol(object): self.kconfig._warn( "the value {} is invalid for {}, which has type {} -- " "assignment ignored" - .format(TRI_TO_STR[value] if value in (0, 1, 2) else + .format(TRI_TO_STR[value] if value in TRI_TO_STR else "'{}'".format(value), _name_and_loc(self), TYPE_TO_STR[self.orig_type])) return False - if self.orig_type in _BOOL_TRISTATE and value in ("y", "m", "n"): - value = STR_TO_TRI[value] - self.user_value = value self._was_set = True |
