Skip to content

Commit

Permalink
Simplify AlreadySeen implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjw296 committed Nov 3, 2022
1 parent 77ff428 commit 239de21
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions testfixtures/comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,19 +492,19 @@ def _shared_mro(x, y):

class AlreadySeen:

def __init__(self, id_, obj_repr, breadcrumb):
def __init__(self, id_, obj, breadcrumb):
self.id = id_
self.obj_repr = obj_repr
self.obj = obj
self.breadcrumb = breadcrumb

def __repr__(self):
return f'<AlreadySeen for {self.obj_repr} at {self.breadcrumb} with id {self.id}>'
return f'<AlreadySeen for {self.obj!r} at {self.breadcrumb} with id {self.id}>'

def __eq__(self, other):
if isinstance(other, AlreadySeen):
return self.breadcrumb == other.breadcrumb
else:
return self.id == id(other)
return self.obj == other


class CompareContext(object):
Expand Down Expand Up @@ -601,7 +601,7 @@ def _break_loops(self, obj, breadcrumb):
id_ = id(obj)
breadcrumb_ = self._seen.get(id_)
if breadcrumb_ is not None:
return AlreadySeen(id_, repr(obj), breadcrumb_)
return AlreadySeen(id_, obj, breadcrumb_)
else:
self._seen[id_] = breadcrumb
return obj
Expand Down

0 comments on commit 239de21

Please sign in to comment.