Skip to content

Commit 9726cab

Browse files
[3.12] Docs: reword dbm.ndbm introduction (#114549) (#114599)
(cherry picked from commit 4cf068e) - add abbreviation directives for NDBM and GDBM - consistently spell NDBM as NDBM - silence broken ndbm class refs - improve accuracy of dbm.ndbm.open() spec - use replacement text for NDBM/GDBM file format incompatibility note
1 parent 4545845 commit 9726cab

File tree

1 file changed

+26
-20
lines changed

1 file changed

+26
-20
lines changed

Doc/library/dbm.rst

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ the Oracle Berkeley DB.
5252
.. |flag_n| replace::
5353
Always create a new, empty database, open for reading and writing.
5454

55+
.. |incompat_note| replace::
56+
The file formats created by :mod:`dbm.gnu` and :mod:`dbm.ndbm` are incompatible
57+
and can not be used interchangeably.
58+
5559
.. function:: open(file, flag='r', mode=0o666)
5660

5761
Open the database file *file* and return a corresponding object.
@@ -157,9 +161,7 @@ functionality like crash tolerance.
157161
except that keys and values are always converted to :class:`bytes` before storing,
158162
and the :meth:`!items` and :meth:`!values` methods are not supported.
159163

160-
.. note::
161-
The file formats created by :mod:`dbm.gnu` and :mod:`dbm.ndbm` are
162-
incompatible and can not be used interchangeably.
164+
.. note:: |incompat_note|
163165

164166
.. exception:: error
165167

@@ -246,29 +248,32 @@ and the :meth:`!items` and :meth:`!values` methods are not supported.
246248

247249
Close the GDBM database.
248250

249-
:mod:`dbm.ndbm` --- Interface based on ndbm
250-
-------------------------------------------
251+
252+
:mod:`dbm.ndbm` --- New Database Manager
253+
----------------------------------------
251254

252255
.. module:: dbm.ndbm
253256
:platform: Unix
254-
:synopsis: The standard "database" interface, based on ndbm.
257+
:synopsis: The New Database Manager
255258

256259
**Source code:** :source:`Lib/dbm/ndbm.py`
257260

258261
--------------
259262

260-
The :mod:`dbm.ndbm` module provides an interface to the Unix "(n)dbm" library.
261-
Dbm objects behave like mappings (dictionaries), except that keys and values are
262-
always stored as bytes. Printing a ``dbm`` object doesn't print the keys and
263-
values, and the :meth:`items` and :meth:`values` methods are not supported.
263+
The :mod:`dbm.ndbm` module provides an interface to the
264+
:abbr:`NDBM (New Database Manager)` library.
265+
:class:`!ndbm` objects behave similar to :term:`mappings <mapping>`,
266+
except that keys and values are always stored as :class:`bytes`,
267+
and the :meth:`!items` and :meth:`!values` methods are not supported.
264268

265-
This module can be used with the "classic" ndbm interface or the GNU GDBM
266-
compatibility interface. On Unix, the :program:`configure` script will attempt
267-
to locate the appropriate header file to simplify building this module.
269+
This module can be used with the "classic" NDBM interface or the
270+
:abbr:`GDBM (GNU dbm)` compatibility interface.
271+
272+
.. note:: |incompat_note|
268273

269274
.. warning::
270275

271-
The ndbm library shipped as part of macOS has an undocumented limitation on the
276+
The NDBM library shipped as part of macOS has an undocumented limitation on the
272277
size of values, which can result in corrupted database files
273278
when storing values larger than this limit. Reading such corrupted files can
274279
result in a hard crash (segmentation fault).
@@ -281,13 +286,14 @@ to locate the appropriate header file to simplify building this module.
281286

282287
.. data:: library
283288

284-
Name of the ``ndbm`` implementation library used.
289+
Name of the NDBM implementation library used.
285290

286291

287-
.. function:: open(filename[, flag[, mode]])
292+
.. function:: open(filename, flag="r", mode=0o666, /)
288293

289-
Open a dbm database and return a ``ndbm`` object. The *filename* argument is the
290-
name of the database file (without the :file:`.dir` or :file:`.pag` extensions).
294+
Open an NDBM database and return an :class:`!ndbm` object.
295+
The *filename* argument is the name of the database file
296+
(without the :file:`.dir` or :file:`.pag` extensions).
291297

292298
The optional *flag* argument must be one of these values:
293299

@@ -303,15 +309,15 @@ to locate the appropriate header file to simplify building this module.
303309
database has to be created. It defaults to octal ``0o666`` (and will be
304310
modified by the prevailing umask).
305311

306-
In addition to the dictionary-like methods, ``ndbm`` objects
312+
In addition to the dictionary-like methods, :class:`!ndbm` objects
307313
provide the following method:
308314

309315
.. versionchanged:: 3.11
310316
Accepts :term:`path-like object` for filename.
311317

312318
.. method:: ndbm.close()
313319

314-
Close the ``ndbm`` database.
320+
Close the NDBM database.
315321

316322

317323
:mod:`dbm.dumb` --- Portable DBM implementation

0 commit comments

Comments
 (0)