Fix bool filter for non-hashable types (#85300)

pull/85308/head
Matt Clay 6 months ago committed by GitHub
parent d3977ebc88
commit c8324aa01a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -98,6 +98,7 @@ _valid_bool_false = {'no', 'off', 'false', '0'}
def to_bool(value: object) -> bool:
"""Convert well-known input values to a boolean value."""
value_to_check: object
if isinstance(value, str):
value_to_check = value.lower() # accept mixed case variants
elif isinstance(value, int): # bool is also an int
@ -105,14 +106,17 @@ def to_bool(value: object) -> bool:
else:
value_to_check = value
if value_to_check in _valid_bool_true:
return True
try:
if value_to_check in _valid_bool_true:
return True
if value_to_check in _valid_bool_false:
return False
if value_to_check in _valid_bool_false:
return False
# if we're still here, the value is unsupported- always fire a deprecation warning
result = value_to_check == 1 # backwards compatibility with the old code which checked: value in ('yes', 'on', '1', 'true', 1)
# if we're still here, the value is unsupported- always fire a deprecation warning
result = value_to_check == 1 # backwards compatibility with the old code which checked: value in ('yes', 'on', '1', 'true', 1)
except TypeError:
result = False
# NB: update the doc string to reflect reality once this fallback is removed
display.deprecated(

@ -366,6 +366,7 @@
- (1.0|bool)==true
- (0.0|bool)==false
- (7|bool)==false
- ({}|bool)==false
- name: Verify to_datetime
assert:

Loading…
Cancel
Save