-
-
Notifications
You must be signed in to change notification settings - Fork 34.4k
the dbm docs are vague about what encoding is used when a str is stored #122996
Copy link
Copy link
Open
Labels
docsDocumentation in the Doc dirDocumentation in the Doc dirextension-modulesC modules in the Modules dirC modules in the Modules dirstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytriagedThe issue has been accepted as valid by a triager.The issue has been accepted as valid by a triager.type-featureA feature request or enhancementA feature request or enhancement
Metadata
Metadata
Assignees
Labels
docsDocumentation in the Doc dirDocumentation in the Doc dirextension-modulesC modules in the Modules dirC modules in the Modules dirstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytriagedThe issue has been accepted as valid by a triager.The issue has been accepted as valid by a triager.type-featureA feature request or enhancementA feature request or enhancement
Projects
Status
In Progress
Status
In Progress
Documentation
The documentation for the dbm module, eg at https://docs.python.org/3.13/library/dbm.html include an example storing keys and values which are of type
str. The documentation says about strings:It is not at all clear to me what "the default encoding" means. For example, one might assume it was the encoding from
locale.getenconding()but I think not. Looking at thedbm.sqlitecode one seesCAST(? AS BLOB)as the insert parameter placeholder. That says to me that the encoding is whatever the database is using, and that is not apparent to me from looking at the code. And I imagine that the other dbm backends may use other, different, choices for the default encoding.Ideally I'd like:
encodingparameter for the dbm.open calls to provide an encoding, with the current (vague but historicly compatible) behaviour if unset, but if provided then an explicit catch ofstrvalues in__setitem__if set, and conversion according to what was providedI can probably make a PR for the second and third items, and the "backend dependent" flavour of the first one.
Linked PRs