sopel-irc / sopel

:robot::speech_balloon: An easy-to-use and highly extensible IRC Bot framework. Formerly Willie.
https://sopel.chat
Other
951 stars 405 forks source link

SopelIdentifierMemory pop() does not cast #2524

Closed half-duplex closed 8 months ago

half-duplex commented 8 months ago

Description

SopelIdentifierMemory automatically casts strings to Identifiers when accessing contents with mem["foo"], but pop() doesn't seem to.

Reproduction steps

>>> from sopel.tools import Identifier, SopelIdentifierMemory
>>> mem = SopelIdentifierMemory()
>>> mem["Foo"] = "bar"
>>> mem["Foo"]
'bar'
>>> mem.pop("Foo")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyError: 'Foo'
>>> mem.pop(Identifier("Foo"))
'bar'

Note the capital F in "Foo" - hashing Identifier("foo") and "foo" seems to match, but not Identifier("Foo") and "Foo".

Expected behavior

pop() performs the same cast as mem["Foo"] and works.

Sopel version

271b306ac328ccea32da333787c00b739021bb39

Installation method

pip install

Python version

3.11.5

dgw commented 8 months ago

Follow-up note from IRC: The whole dict API should be checked when resolving this.

dgw commented 8 months ago

Went down the doc page testing each operation listed under dict and found the following:

…I might not actually finish #2525 today, lol. That's a lot of stuff to figure out how to handle, then write unit tests for. 😅