Skip to content

Commit 028797b

Browse files
committed
Switching to tuples removed this case
Checking if an element is in a small tuple is fast enough.
1 parent 1967be0 commit 028797b

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

src/attr/converters.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,11 @@ def to_bool(val):
131131
"""
132132
if isinstance(val, str):
133133
val = val.lower()
134-
try:
135-
if val in (True, "true", "t", "yes", "y", "on", "1", 1):
136-
return True
137-
if val in (False, "false", "f", "no", "n", "off", "0", 0):
138-
return False
139-
except TypeError:
140-
# Raised when "val" is not hashable (e.g., lists)
141-
pass
134+
135+
if val in (True, "true", "t", "yes", "y", "on", "1", 1):
136+
return True
137+
if val in (False, "false", "f", "no", "n", "off", "0", 0):
138+
return False
142139

143140
msg = f"Cannot convert value to bool: {val!r}"
144141
raise ValueError(msg)

0 commit comments

Comments
 (0)