Skip to content

Commit b21ca05

Browse files
authored
Merge pull request #2900 from alicevision/dev/callable
[core] use callable instead of checking for FunctionType instance type
2 parents 0438f49 + 1bd0f3d commit b21ca05

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

meshroom/core/attribute.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import os
44
import re
55
import weakref
6-
import types
76
import logging
87

98
from collections.abc import Iterable, Sequence
@@ -158,7 +157,7 @@ def _setValue(self, value):
158157
if isinstance(value, Attribute) or Attribute.isLinkExpression(value):
159158
# if we set a link to another attribute
160159
self._value = value
161-
elif isinstance(value, types.FunctionType):
160+
elif callable(value):
162161
# evaluate the function
163162
self._value = value(self)
164163
else:
@@ -216,7 +215,7 @@ def getDefaultValue(self):
216215
"""
217216
Get the attribute default value.
218217
"""
219-
if isinstance(self._desc.value, types.FunctionType):
218+
if callable(self._desc.value):
220219
try:
221220
return self._desc.value(self)
222221
except Exception as e:
@@ -282,7 +281,7 @@ def _isValid(self):
282281
- If it is a function, execute it and return the result
283282
- Otherwise, simply return true
284283
"""
285-
if isinstance(self._desc.validValue, types.FunctionType):
284+
if callable(self._desc.validValue):
286285
try:
287286
return self._desc.validValue(self.node)
288287
except Exception:
@@ -343,7 +342,7 @@ def updateInternals(self):
343342
self._setEnabled(self._getEnabled())
344343

345344
def _getEnabled(self) -> bool:
346-
if isinstance(self._desc.enabled, types.FunctionType):
345+
if callable(self._desc.enabled):
347346
try:
348347
return self._desc.enabled(self.node)
349348
except Exception:

meshroom/core/desc/attribute.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import ast
22
import distutils.util
33
import os
4-
import types
54
from collections.abc import Iterable
65

76
from meshroom.common import BaseObject, JSValue, Property, Variant, VariantList
@@ -29,7 +28,7 @@ def __init__(self, name, label, description, value, advanced, semantic, group, e
2928
self._visible = visible
3029
self._exposed = exposed
3130
self._isExpression = (isinstance(self._value, str) and "{" in self._value) \
32-
or isinstance(self._value, types.FunctionType)
31+
or callable(self._value)
3332
self._isDynamicValue = (self._value is None)
3433
self._valueType = None
3534

meshroom/core/node.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import re
1111
import shutil
1212
import time
13-
import types
1413
import uuid
1514
from collections import namedtuple, OrderedDict
1615
from enum import Enum, auto
@@ -963,7 +962,7 @@ def _buildCmdVars(self):
963962
def _buildAttributeCmdVars(cmdVars, name, attr):
964963
if attr.enabled:
965964
group = attr.desc.group(attr.node) \
966-
if isinstance(attr.desc.group, types.FunctionType) else attr.desc.group
965+
if callable(attr.desc.group) else attr.desc.group
967966
if group is not None:
968967
# If there is a valid command line "group"
969968
v = attr.getValueStr(withQuotes=True)

0 commit comments

Comments
 (0)