mailgun / expiringdict

Dictionary with auto-expiring values for caching purposes.
Apache License 2.0
347 stars 76 forks source link

`KeyError` during string representation in Python 3.12 #55

Open AndrewKvalheim opened 4 months ago

AndrewKvalheim commented 4 months ago

In Python 3.12, representation as a string fails with KeyError:

$ python
Python 3.12.4 (main, Jun  6 2024, 18:26:44) [GCC 13.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from expiringdict import ExpiringDict
>>> expiring_dict = ExpiringDict(1, 0)
>>> expiring_dict["foo"] = "bar"
>>> expiring_dict
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "…/expiringdict/__init__.py", line 86, in __getitem__
    raise KeyError(key)
KeyError: 'foo'

The underlying cause is that string representation now copies the dict, and this action fails in both Python 3.11 and 3.12:

$ python
Python 3.11.9 (main, Apr  2 2024, 08:25:04) [GCC 13.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from expiringdict import ExpiringDict
>>> expiring_dict = ExpiringDict(1, 0)
>>> expiring_dict["foo"] = "bar"
>>> dict(expiring_dict)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "…/expiringdict/__init__.py", line 86, in __getitem__
    raise KeyError(key)
KeyError: 'foo'