@@ -95,6 +95,10 @@ The object returned by :func:`~dbm.open` supports the same basic functionality a
95
95
deleted, and the :keyword: `in ` operator and the :meth: `!keys ` method are
96
96
available, as well as :meth: `!get ` and :meth: `!setdefault ` methods.
97
97
98
+ .. note ::
99
+ Unlike the standard :class: `dict ` type, the :meth: `dict.setdefault ` method
100
+ for DBM objects requires both the *key * and *default * parameters.
101
+
98
102
Key and values are always stored as :class: `bytes `. This means that when
99
103
strings are used they are implicitly converted to the default encoding before
100
104
being stored.
@@ -204,6 +208,14 @@ or any other SQLite browser, including the SQLite CLI.
204
208
205
209
.. versionadded :: next
206
210
211
+ .. method :: sqlite3.setdefault(key, default)
212
+
213
+ If *key * is in the database, return its value. If not, insert *key * with
214
+ a value of *default * and return *default *. Unlike :meth: `dict.setdefault `,
215
+ both parameters are required. Calling ``setdefault(key) `` with only a key
216
+ will raise :exc: `dbm.sqlite3.error `.
217
+
218
+
207
219
:mod: `dbm.gnu ` --- GNU database manager
208
220
---------------------------------------
209
221
@@ -323,6 +335,13 @@ functionality like crash tolerance.
323
335
324
336
.. versionadded :: 3.13
325
337
338
+ .. method :: gdbm.setdefault(key, default)
339
+
340
+ If *key * is in the database, return its value. If not, insert *key * with
341
+ a value of *default * and return *default *. Unlike :meth: `dict.setdefault `,
342
+ both parameters are required. Calling ``setdefault(key) `` with only a key
343
+ will raise :exc: `TypeError `.
344
+
326
345
327
346
:mod: `dbm.ndbm ` --- New Database Manager
328
347
----------------------------------------
@@ -400,6 +419,13 @@ This module can be used with the "classic" NDBM interface or the
400
419
401
420
.. versionadded :: 3.13
402
421
422
+ .. method :: ndbm.setdefault(key, default)
423
+
424
+ If *key * is in the database, return its value. If not, insert *key * with
425
+ a value of *default * and return *default *. Unlike :meth: `dict.setdefault `,
426
+ both parameters are required. Calling ``setdefault(key) `` with only a key
427
+ will raise :exc: `_dbm.error `.
428
+
403
429
404
430
:mod: `dbm.dumb ` --- Portable DBM implementation
405
431
-----------------------------------------------
@@ -501,3 +527,10 @@ The :mod:`!dbm.dumb` module defines the following:
501
527
that this factor changes for each :mod: `dbm ` submodule.
502
528
503
529
.. versionadded :: next
530
+
531
+ .. method :: dumbdbm.setdefault(key, default)
532
+
533
+ If *key * is in the database, return its value. If not, insert *key * with
534
+ a value of *default * and return *default *. Unlike :meth: `dict.setdefault `,
535
+ both parameters are required. Calling ``setdefault(key) `` with only a key
536
+ will raise :exc: `TypeError `.
0 commit comments