Skip to content

Commit

Permalink
Explicitly define printable representation
Browse files Browse the repository at this point in the history
In Python 3.12 the implementation of OrderedDict.__repr__ changed such
that ExpiringDict.__repr__ may trigger expiration and raise KeyError. To
avoid this, explicitly implement ExpiringDict.__repr__ using validated
ExpiringDict.items().

Resolves mailgun#55
  • Loading branch information
AndrewKvalheim committed Jul 12, 2024
1 parent db04243 commit 976faf3
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions expiringdict/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ def __getitem__(self, key, with_age=False):
del self[key]
raise KeyError(key)

def __repr__(self):
return f"{self.__class__.__name__}({self.items()})"

def __setitem__(self, key, value, set_time=None):
""" Set d[key] to value. """
with self.lock:
Expand Down

0 comments on commit 976faf3

Please sign in to comment.