Skip to content

Commit

Permalink
Refactor __eq__ method in Simulation
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewFilipovich committed Jul 13, 2022
1 parent 7e15497 commit 2f96904
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions pycharge/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,16 @@ def __init__(

def __eq__(self, other: Any) -> bool:
# Check E_external and B_external are the same
if self.E_external is None or other.E_external is None:
same_E_external = self.E_external == other.E_external
else:
try:
same_E_external = (inspect.getsource(self.E_external)
== inspect.getsource(other.E_external))
if self.B_external is None or other.B_external is None:
same_B_external = self.B_external == other.B_external
else:
except TypeError: # If one or both E_external is None
same_E_external = self.E_external == other.E_external
try:
same_B_external = (inspect.getsource(self.B_external)
== inspect.getsource(other.B_external))
except TypeError: # If one or both B_external is None
same_B_external = self.B_external == other.B_external

return (isinstance(other, self.__class__) and self.dt == other.dt
and self.all_charges == other.all_charges
Expand Down

0 comments on commit 2f96904

Please sign in to comment.