MCPcopy Index your code
hub / github.com/dbcli/mycli / str_to_bool

Function str_to_bool

mycli/config.py:208–223  ·  view source on GitHub ↗

Convert a string value to its corresponding boolean value.

(s: str | bool)

Source from the content-addressed store, hash-verified

206
207
208def str_to_bool(s: str | bool) -> bool:
209 """Convert a string value to its corresponding boolean value."""
210 if isinstance(s, bool):
211 return s
212 elif not isinstance(s, str):
213 raise TypeError("argument must be a string")
214
215 true_values = ("true", "on", "1")
216 false_values = ("false", "off", "0")
217
218 if s.lower() in true_values:
219 return True
220 elif s.lower() in false_values:
221 return False
222 else:
223 raise ValueError(f'not a recognized boolean value: {s}')
224
225
226def strip_matching_quotes(s: str) -> str:

Callers 3

run_from_cli_argsFunction · 0.90
connectMethod · 0.90
test_str_to_boolFunction · 0.90

Calls

no outgoing calls

Tested by 1

test_str_to_boolFunction · 0.72