In Lib/dbm/dumb.py, _Database.setitem and related methods accept
bytearray keys (the isinstance check includes bytearray), but the
in-memory index is a dict, and bytearray is not hashable:
import dbm.dumb, tempfile, os
d = tempfile.mkdtemp()
db = dbm.dumb.open(os.path.join(d, 'testdb'), 'c')
db[bytearray(b'key')] = b'value'
# TypeError: unhashable type: 'bytearray'
The same problem affects getitem, delitem, and contains.
The isinstance check should either reject bytearray, or convert it to
bytes before use.
Discovered while reviewing the module with an AI assistant.
Linked PRs
In Lib/dbm/dumb.py, _Database.setitem and related methods accept
bytearray keys (the isinstance check includes bytearray), but the
in-memory index is a dict, and bytearray is not hashable:
The same problem affects getitem, delitem, and contains.
The isinstance check should either reject bytearray, or convert it to
bytes before use.
Discovered while reviewing the module with an AI assistant.
Linked PRs