8000 [3.12] Docs: rework the dbm.dumb introduction (GH-114550) (#114620) · python/cpython@bf35ac1 · GitHub
[go: up one dir, main page]

Skip to content 10000

Commit bf35ac1

Browse files
[3.12] Docs: rework the dbm.dumb introduction (GH-114550) (#114620)
(cherry picked from commit 6c2b419) - consistently use correct parameter markup - consistently use submodule name as database name - improve accuracy of the dbm.dumb.open() spec - remove dumbdbm class refs and replace them with generic "database object" - use parameter list for dbm.dumb.open() (cherry picked from commit 6c2b419) Co-authored-by: Erlend E. Aasland <erlend@python.org>
1 parent 74bd566 commit bf35ac1

File tree

1 file changed

+36
-30
lines changed

1 file changed

+36
-30
lines changed

Doc/library/dbm.rst

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -339,61 +339,67 @@ This module can be used with the "classic" NDBM interface or the
339339

340340
--------------
341341

342-
The :mod:`dbm.dumb` module provides a persistent dictionary-like interface which
343-
is written entirely in Python. Unlike other modules such as :mod:`dbm.gnu` no
344-
external library is required. As with other persistent mappings, the keys and
345-
values are always stored as bytes.
346-
347-
The module defines the following:
342+
The :mod:`dbm.dumb` module provides a persistent :class:`dict`-like
343+
interface which is written entirely in Python.
344+
Unlike other :mod:`dbm` backends, such as :mod:`dbm.gnu`, no
345+
external library is required.
346+
As with other :mod:`dbm` backends,
347+
the keys and values are always stored as :class:`bytes`.
348348

349+
The :mod:`!dbm.dumb` module defines the following:
349350

350351
.. exception:: error
351352

352353
Raised on :mod:`dbm.dumb`-specific errors, such as I/O errors. :exc:`KeyError` is
353354
raised for general mapping errors like specifying an incorrect key.
354355

355356

356-
.. function:: open(filename[, flag[, mode]])
357+
.. function:: open(filename, flag="c", mode=0o666)
357358

358-
Open a ``dumbdbm`` database and return a dumbdbm object. The *filename* argument is
359-
the basename of the database file (without any specific extensions). When a
360-
dumbdbm database is created, files with :file:`.dat` and :file:`.dir` extensions
361-
are created.
359+
Open a :mod:`!dbm.dumb` database.
360+
The returned database object behaves similar to a :term:`mapping`,
361+
in addition to providing :meth:`~dumbdbm.sync` and :meth:`~dumbdbm.close`
362+
methods.
362363

363-
The optional *flag* argument can be:
364+
:param filename:
365+
The basename of the database file (without extensions).
366+
A new database creates the following files:
364367

365-
.. csv-table::
366-
:header: "Value", "Meaning"
368+
- :file:`{filename}.dat`
369+
- :file:`{filename}.dir`
370+
:type database: :term:`path-like object`
367371

368-
``'r'``, |flag_r|
369-
``'w'``, |flag_w|
370-
``'c'`` (default), |flag_c|
371-
``'n'``, |flag_n|
372+
:param str flag:
373+
.. csv-table::
374+
:header: "Value", "Meaning"
372375

373-
The optional *mode* argument is the Unix mode of the file, used only when the
374-
database has to be created. It defaults to octal ``0o666`` (and will be modified
375-
by the prevailing umask).
376+
``'r'``, |flag_r|
377+
``'w'``, |flag_w|
378+
``'c'`` (default), |flag_c|
379+
``'n'``, |flag_n|
380+
381+
:param int mode:
382+
The Unix file access mode of the file (default: ``0o666``),
383+
used only when the database has to be created.
376384

377385
.. warning::
378386
It is possible to crash the Python interpreter when loading a database
379387
with a sufficiently large/complex entry due to stack depth limitations in
380388
Python's AST compiler.
381389

382390
.. versionchanged:: 3.5
383-
:func:`.open` always creates a new database when the flag has the value
384-
``'n'``.
391+
:func:`open` always creates a new database when *flag* is ``'n'``.
385392

386393
.. versionchanged:: 3.8
387-
A database opened with flags ``'r'`` is now read-only. Opening with
388-
flags ``'r'`` and ``'w'`` no longer creates a database if it does not
389-
exist.
394+
A database opened read-only if *flag* is ``'r'``.
395+
A database is not created if it does not exist if *flag* is ``'r'`` or ``'w'``.
390396

391397
.. versionchanged:: 3.11
392-
Accepts :term:`path-like object` for filename.
398+
*filename* accepts a :term:`path-like object`.
393399

394400
In addition to the methods provided by the
395-
:class:`collections.abc.MutableMapping` class, :class:`dumbdbm` objects
396-
provide the following methods:
401+
:class:`collections.abc.MutableMapping` class,
402+
the following methods are provided:
397403

398404
.. method:: dumbdbm.sync()
399405

@@ -402,5 +408,5 @@ The module defines the following:
402408

403409
.. method:: dumbdbm.close()
404410

405-
Close the ``dumbdbm`` database.
411+
Close the database.
406412

0 commit comments

Comments
 (0)
0