Skip to content

Commit 0003635

Browse files
committed
Added idempotent and None-safe version of strict_bool
1 parent 057ee4e commit 0003635

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

src/bd2k/util/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,24 @@ def rfc3339_datetime_re( anchor=True ):
159159

160160

161161
def strict_bool( s ):
162+
"""
163+
Variant of bool() that only accepts two possible string values.
164+
"""
162165
if s == 'True':
163166
return True
164167
elif s == 'False':
165168
return False
166169
else:
167170
raise ValueError( s )
171+
172+
173+
def less_strict_bool( x ):
174+
"""
175+
Idempotent and None-safe version of strict_bool.
176+
"""
177+
if x is None:
178+
return False
179+
elif x is True or x is False:
180+
return x
181+
else:
182+
return strict_bool( x )

0 commit comments

Comments
 (0)