Skip to content

Commit

Permalink
Switch to checking isinstance instead of package name
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilReinhold committed Aug 27, 2024
1 parent 2df694b commit 6de16a9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion oqpy/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,8 @@ def expr_matches(a: Any, b: Any) -> bool:
if a.keys() != b.keys():
return False
return all(expr_matches(va, b[k]) for k, va in a.items())
if hasattr(a, "__dict__") and type(a).__module__.startswith("oqpy"):
if isinstance(a, OQPyExpression):
# Bypass `__eq__` which is overloaded on OQPyExpressions
return expr_matches(a.__dict__, b.__dict__)
else:
return a == b
Expand Down
7 changes: 7 additions & 0 deletions tests/test_directives.py
Original file line number Diff line number Diff line change
Expand Up @@ -2649,3 +2649,10 @@ def __eq__(self, other):
x1._entity = MyEntityNoEq()
x2._entity = x1._entity
oqpy.base.expr_matches(x1, x2)

class MyFloatVar(oqpy.FloatVar):
...

x1 = MyFloatVar(3, name="x")
x2 = MyFloatVar(3, name="x")
assert oqpy.base.expr_matches(x1, x2)

0 comments on commit 6de16a9

Please sign in to comment.