Switching to tuples removed this case

Checking if an element is in a small tuple is fast enough.
This commit is contained in:
Hynek Schlawack 2024-03-17 12:27:04 +01:00
parent 1967be0eb6
commit 028797bd24
No known key found for this signature in database
1 changed files with 5 additions and 8 deletions

View File

@ -131,14 +131,11 @@ def to_bool(val):
"""
if isinstance(val, str):
val = val.lower()
try:
if val in (True, "true", "t", "yes", "y", "on", "1", 1):
return True
if val in (False, "false", "f", "no", "n", "off", "0", 0):
return False
except TypeError:
# Raised when "val" is not hashable (e.g., lists)
pass
if val in (True, "true", "t", "yes", "y", "on", "1", 1):
return True
if val in (False, "false", "f", "no", "n", "off", "0", 0):
return False
msg = f"Cannot convert value to bool: {val!r}"
raise ValueError(msg)