Message315898
setdefault() is not implemented directly in dbm.gdbm and dmb.ndbm database classes. It is inherited from MutableMapping:
def setdefault(self, key, default=None):
try:
return self[key]
except KeyError:
self[key] = default
return default
But since assigning is supported only for bytes and str, setdefault(key) fails if the key was not set before. It works only if the key was set or with the second argument. d.setdefault(key) is equivalent to d[key] except that it raises a weird TypeError instead of KeyError.
There are two ways of solving this problem:
1. Reimplement setdefault() for dbm.gdbm and dmb.ndbm database classes with default=b'' by default.
2. Make the second argument mandatory.
In both cases this violates the MutableMapping interface. |
|
Date |
User |
Action |
Args |
2018-04-29 14:00:31 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka |
2018-04-29 14:00:31 | serhiy.storchaka | set | messageid: <1525010431.96.0.682650639539.issue33385@psf.upfronthosting.co.za> |
2018-04-29 14:00:31 | serhiy.storchaka | link | issue33385 messages |
2018-04-29 14:00:31 | serhiy.storchaka | create | |
|