Skip to content

Commit 36c53a7

Browse files
authored
__instancecheck__ performance improvements
1 parent 31094f4 commit 36c53a7

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

unification/variable.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
import weakref
22
from abc import ABCMeta
3-
from contextlib import contextmanager, suppress
3+
from contextlib import contextmanager
44

55
_glv = _global_logic_variables = set()
66

77

88
class LVarType(ABCMeta):
99
def __instancecheck__(self, o):
10-
with suppress(TypeError):
11-
return issubclass(type(o), (Var, LVarType)) or o in _glv
12-
return False
10+
if issubclass(type(o), Var):
11+
return True
12+
13+
try:
14+
return o in _glv
15+
except TypeError:
16+
return False
1317

1418

1519
class Var(metaclass=LVarType):

0 commit comments

Comments
 (0)