Skip to content

Commit

Permalink
[core] more generic str to bool conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiencastan committed Apr 11, 2022
1 parent 655dad9 commit 2a32f39
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion meshroom/core/desc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import os
import psutil
import ast
import distutils


class Attribute(BaseObject):
"""
Expand Down Expand Up @@ -191,7 +193,8 @@ def __init__(self, name, label, description, value, uid, group='allParams', adva

def validateValue(self, value):
try:
return bool(int(value)) # int cast is useful to handle string values ('0', '1')
# use distutils.util.strtobool to handle (1/0, true/false, on/off, y/n)
return bool(distutils.util.strtobool(value))
except:
raise ValueError('BoolParam only supports bool value (param:{}, value:{}, type:{})'.format(self.name, value, type(value)))

Expand Down

0 comments on commit 2a32f39

Please sign in to comment.