What could be a way to avoid isinstance
in the following code, targeting to parse arbitrary logic consisting of (1) conditions, (2) and_
or or_
strings, (3) and nested tuples thereof like:
t = ["a","and_",("b",'or_','a'),'and_',('a','and_','b'),'or_','c']
# @njit
def _eval(d):
while len(d) > 1:
X = {"a": True, "b": False, "c": True}
a, b, c = d[:3]
d = d[3:]
v1 = X[a] if a in X else (_eval(a) if isinstance(a, tuple) else a)
v2 = X[c] if c in X else (_eval(c) if isinstance(c, tuple) else c)
d = [v1 & v2 if b == "and_" else v1 | v2] + list(d)
return d[0]
# True
Thanks!