From 976faf3664d54049e443aca054f5819db834577b Mon Sep 17 00:00:00 2001 From: Andrew Kvalheim Date: Fri, 12 Jul 2024 14:22:23 -0700 Subject: [PATCH] Explicitly define printable representation 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 #55 --- expiringdict/__init__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/expiringdict/__init__.py b/expiringdict/__init__.py index 90d086b..add8223 100755 --- a/expiringdict/__init__.py +++ b/expiringdict/__init__.py @@ -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: