Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyError during string representation in Python 3.12 #55

Open
AndrewKvalheim opened this issue Jul 12, 2024 · 0 comments
Open

KeyError during string representation in Python 3.12 #55

AndrewKvalheim opened this issue Jul 12, 2024 · 0 comments

Comments

@AndrewKvalheim
Copy link

AndrewKvalheim commented Jul 12, 2024

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'
AndrewKvalheim added a commit to AndrewKvalheim/expiringdict that referenced this issue Jul 12, 2024
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant