This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients serhiy.storchaka
Date 2018-04-29.14:00:31
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1525010431.96.0.682650639539.issue33385@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2018-04-29 14:00:31serhiy.storchakasetrecipients: + serhiy.storchaka
2018-04-29 14:00:31serhiy.storchakasetmessageid: <1525010431.96.0.682650639539.issue33385@psf.upfronthosting.co.za>
2018-04-29 14:00:31serhiy.storchakalinkissue33385 messages
2018-04-29 14:00:31serhiy.storchakacreate