Skip to content

Commit

Permalink
Switching to tuples removed this case
Browse files Browse the repository at this point in the history
Checking if an element is in a small tuple is fast enough.
  • Loading branch information
hynek committed Mar 17, 2024
1 parent 1967be0 commit 028797b
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/attr/converters.py
Expand Up @@ -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)

0 comments on commit 028797b

Please sign in to comment.