the dbm docs are vague about what encoding is used when a str is stored
Personne n'a encore pris cette issue.
- Langage dominant
- Python
- Étoiles
- 77.2k
- Forks
- 35.9k
- Métriques de merge des PR
- Métriques de PR en attente
Description
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:
Key and values are always stored as [bytes](https://docs.python.org/3.13/library/stdtypes.html#bytes).
This means that when strings are used they are implicitly converted
to the default encoding before being stored.
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 the dbm.sqlite code one sees CAST(? 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:
- an explicit statement about how the encoding is chosen if that is possible, or a statement that this is backend and possibly current-locale dependent otherwise
- a statement that users should probably always do their own conversion to bytes before storing values if they want control
- possibly an optional
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 provided
I can probably make a PR for the second and third items, and the "backend dependent" flavour of the first one.
Linked PRs
- gh-138030
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par la documentation de dbm à l’adresse docs.python.org/3.13/library/dbm.html et examinez la gestion de CAST(? AS BLOB) dans le code de dbm.sqlite. Comparez la manière dont les backends dbm traitent les valeurs str, puis mettez à jour la documentation pour expliquer le comportement de l’encodage et recommander de convertir les valeurs en bytes lorsque les appelants ont besoin de contrôle. Consultez le PR lié gh-138030 avant de commencer.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- python
- Domaine
- documentation
- Type d'issue
- Documentation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 30/100