mirror of
https://github.com/zebrajr/ansible.git
synced 2025-12-06 12:19:53 +01:00
Fix bool filter for non-hashable types (#85300)
This commit is contained in:
parent
d3977ebc88
commit
c8324aa01a
|
|
@ -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,6 +106,7 @@ def to_bool(value: object) -> bool:
|
|||
else:
|
||||
value_to_check = value
|
||||
|
||||
try:
|
||||
if value_to_check in _valid_bool_true:
|
||||
return True
|
||||
|
||||
|
|
@ -113,6 +115,8 @@ def to_bool(value: object) -> bool:
|
|||
|
||||
# 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…
Reference in New Issue
Block a user