Get a setting value as a boolean. ``1``, ``'1'``, `True`` and ``'True'`` return ``True``, while ``0``, ``'0'``, ``False``, ``'False'`` and ``None`` return ``False``. For example, settings populated through environment variables set to ``'0'`` will return ``
(self, name: _SettingsKey, default: bool = False)
| 173 | return self[name] if self[name] is not None else default |
| 174 | |
| 175 | def getbool(self, name: _SettingsKey, default: bool = False) -> bool: |
| 176 | """ |
| 177 | Get a setting value as a boolean. |
| 178 | |
| 179 | ``1``, ``'1'``, `True`` and ``'True'`` return ``True``, |
| 180 | while ``0``, ``'0'``, ``False``, ``'False'`` and ``None`` return ``False``. |
| 181 | |
| 182 | For example, settings populated through environment variables set to |
| 183 | ``'0'`` will return ``False`` when using this method. |
| 184 | |
| 185 | :param name: the setting name |
| 186 | :type name: str |
| 187 | |
| 188 | :param default: the value to return if no setting is found |
| 189 | :type default: object |
| 190 | """ |
| 191 | got = self.get(name, default) |
| 192 | try: |
| 193 | return bool(int(got)) |
| 194 | except ValueError: |
| 195 | if got in {"True", "true"}: |
| 196 | return True |
| 197 | if got in {"False", "false"}: |
| 198 | return False |
| 199 | raise ValueError( |
| 200 | "Supported values for boolean settings " |
| 201 | "are 0/1, True/False, '0'/'1', " |
| 202 | "'True'/'False' and 'true'/'false'" |
| 203 | ) from None |
| 204 | |
| 205 | def getint(self, name: _SettingsKey, default: int = 0) -> int: |
| 206 | """ |
no test coverage detected