Skip to content

Commit e20c3fa

Browse files
committed
[core] use callable instead of checking for FunctionType instance type
1 parent 0438f49 commit e20c3fa

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

meshroom/core/attribute.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def _setValue(self, value):
158158
if isinstance(value, Attribute) or Attribute.isLinkExpression(value):
159159
# if we set a link to another attribute
160160
self._value = value
161-
elif isinstance(value, types.FunctionType):
161+
elif callable(value):
162162
# evaluate the function
163163
self._value = value(self)
164164
else:
@@ -216,7 +216,7 @@ def getDefaultValue(self):
216216
"""
217217
Get the attribute default value.
218218
"""
219-
if isinstance(self._desc.value, types.FunctionType):
219+
if callable(self._desc.value):
220220
try:
221221
return self._desc.value(self)
222222
except Exception as e:
@@ -282,7 +282,7 @@ def _isValid(self):
282282
- If it is a function, execute it and return the result
283283
- Otherwise, simply return true
284284
"""
285-
if isinstance(self._desc.validValue, types.FunctionType):
285+
if callable(self._desc.validValue):
286286
try:
287287
return self._desc.validValue(self.node)
288288
except Exception:
@@ -343,7 +343,7 @@ def updateInternals(self):
343343
self._setEnabled(self._getEnabled())
344344

345345
def _getEnabled(self) -> bool:
346-
if isinstance(self._desc.enabled, types.FunctionType):
346+
if callable(self._desc.enabled):
347347
try:
348348
return self._desc.enabled(self.node)
349349
except Exception:

meshroom/core/desc/attribute.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def __init__(self, name, label, description, value, advanced, semantic, group, e
2929
self._visible = visible
3030
self._exposed = exposed
3131
self._isExpression = (isinstance(self._value, str) and "{" in self._value) \
32-
or isinstance(self._value, types.FunctionType)
32+
or callable(self._value)
3333
self._isDynamicValue = (self._value is None)
3434
self._valueType = None
3535

meshroom/core/node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,7 @@ def _buildCmdVars(self):
963963
def _buildAttributeCmdVars(cmdVars, name, attr):
964964
if attr.enabled:
965965
group = attr.desc.group(attr.node) \
966-
if isinstance(attr.desc.group, types.FunctionType) else attr.desc.group
966+
if callable(attr.desc.group) else attr.desc.group
967967
if group is not None:
968968
# If there is a valid command line "group"
969969
v = attr.getValueStr(withQuotes=True)

0 commit comments

Comments
 (0)