Skip to content

Commit 8d334ce

Browse files
committed
allow for casting str to bool
1 parent 30974f8 commit 8d334ce

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

plexapi/utils.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,18 @@ def registerPlexObject(cls):
5959

6060
def cast(func, value):
6161
""" Cast the specified value to the specified type (returned by func). Currently this
62-
only support int, float, bool. Should be extended if needed.
62+
only support str, int, float, bool. Should be extended if needed.
6363
6464
Parameters:
6565
func (func): Calback function to used cast to type (int, bool, float).
6666
value (any): value to be cast and returned.
6767
"""
6868
if value is not None:
6969
if func == bool:
70-
return bool(int(value))
70+
try:
71+
return bool(int(value))
72+
except ValueError:
73+
return bool(value)
7174
elif func in (int, float):
7275
try:
7376
return func(value)

0 commit comments

Comments
 (0)