Sets the user value of the symbol. Equal in effect to assigning the value to the symbol within a .config file. For bool and tristate symbols, use the 'assignable' attribute to check which values can currently be assigned. Setting values outside 'assignable'
(self, value)
| 4596 | return self.name + " " + _locs(self) |
| 4597 | |
| 4598 | def set_value(self, value): |
| 4599 | """ |
| 4600 | Sets the user value of the symbol. |
| 4601 | |
| 4602 | Equal in effect to assigning the value to the symbol within a .config |
| 4603 | file. For bool and tristate symbols, use the 'assignable' attribute to |
| 4604 | check which values can currently be assigned. Setting values outside |
| 4605 | 'assignable' will cause Symbol.user_value to differ from |
| 4606 | Symbol.str/tri_value (be truncated down or up). |
| 4607 | |
| 4608 | Setting a choice symbol to 2 (y) sets Choice.user_selection to the |
| 4609 | choice symbol in addition to setting Symbol.user_value. |
| 4610 | Choice.user_selection is considered when the choice is in y mode (the |
| 4611 | "normal" mode). |
| 4612 | |
| 4613 | Other symbols that depend (possibly indirectly) on this symbol are |
| 4614 | automatically recalculated to reflect the assigned value. |
| 4615 | |
| 4616 | value: |
| 4617 | The user value to give to the symbol. For bool and tristate symbols, |
| 4618 | n/m/y can be specified either as 0/1/2 (the usual format for tristate |
| 4619 | values in Kconfiglib) or as one of the strings "n", "m", or "y". For |
| 4620 | other symbol types, pass a string. |
| 4621 | |
| 4622 | Note that the value for an int/hex symbol is passed as a string, e.g. |
| 4623 | "123" or "0x0123". The format of this string is preserved in the |
| 4624 | output. |
| 4625 | |
| 4626 | Values that are invalid for the type (such as "foo" or 1 (m) for a |
| 4627 | BOOL or "0x123" for an INT) are ignored and won't be stored in |
| 4628 | Symbol.user_value. Kconfiglib will print a warning by default for |
| 4629 | invalid assignments, and set_value() will return False. |
| 4630 | |
| 4631 | Returns True if the value is valid for the type of the symbol, and |
| 4632 | False otherwise. This only looks at the form of the value. For BOOL and |
| 4633 | TRISTATE symbols, check the Symbol.assignable attribute to see what |
| 4634 | values are currently in range and would actually be reflected in the |
| 4635 | value of the symbol. For other symbol types, check whether the |
| 4636 | visibility is non-n. |
| 4637 | """ |
| 4638 | if self.orig_type in _BOOL_TRISTATE and value in STR_TO_TRI: |
| 4639 | value = STR_TO_TRI[value] |
| 4640 | |
| 4641 | # If the new user value matches the old, nothing changes, and we can |
| 4642 | # avoid invalidating cached values. |
| 4643 | # |
| 4644 | # This optimization is skipped for choice symbols: Setting a choice |
| 4645 | # symbol's user value to y might change the state of the choice, so it |
| 4646 | # wouldn't be safe (symbol user values always match the values set in a |
| 4647 | # .config file or via set_value(), and are never implicitly updated). |
| 4648 | if value == self.user_value and not self.choice: |
| 4649 | self._was_set = True |
| 4650 | return True |
| 4651 | |
| 4652 | # Check if the value is valid for our type |
| 4653 | if not (self.orig_type is BOOL and value in (2, 0) or |
| 4654 | self.orig_type is TRISTATE and value in TRI_TO_STR or |
| 4655 | value.__class__ is str and |
no test coverage detected