Actual explicit value-setting API call. Sets ``self.raw_value`` to ``value`` directly. Sets ``self.value`` to ``self.kind(value)``, unless: - ``cast=False``, in which case the raw value is also used. - ``self.kind==list``, in which case the value is append
(self, value: Any, cast: bool = True)
| 131 | self.set_value(arg, cast=True) |
| 132 | |
| 133 | def set_value(self, value: Any, cast: bool = True) -> None: |
| 134 | """ |
| 135 | Actual explicit value-setting API call. |
| 136 | |
| 137 | Sets ``self.raw_value`` to ``value`` directly. |
| 138 | |
| 139 | Sets ``self.value`` to ``self.kind(value)``, unless: |
| 140 | |
| 141 | - ``cast=False``, in which case the raw value is also used. |
| 142 | - ``self.kind==list``, in which case the value is appended to |
| 143 | ``self.value`` instead of cast & overwritten. |
| 144 | - ``self.incrementable==True``, in which case the value is ignored and |
| 145 | the current (assumed int) value is simply incremented. |
| 146 | |
| 147 | .. versionadded:: 1.0 |
| 148 | """ |
| 149 | self.raw_value = value |
| 150 | # Default to do-nothing/identity function |
| 151 | func = lambda x: x |
| 152 | # If cast, set to self.kind, which should be str/int/etc |
| 153 | if cast: |
| 154 | func = self.kind |
| 155 | # If self.kind is a list, append instead of using cast func. |
| 156 | if self.kind is list: |
| 157 | func = lambda x: self.value + [x] |
| 158 | # If incrementable, just increment. |
| 159 | if self.incrementable: |
| 160 | # TODO: explode nicely if self.value was not an int to start |
| 161 | # with |
| 162 | func = lambda x: self.value + 1 |
| 163 | self._value = func(value) |
| 164 | |
| 165 | @property |
| 166 | def got_value(self) -> bool: |
no outgoing calls
no test coverage detected