python / python/cpython

the dbm docs are vague about what encoding is used when a str is stored

Aberta
#122,996 0 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

docs extension-modules stdlib triaged type-feature
Linguagem predominante
Python
Estrelas
77.2k
Forks
36k
Métricas de merge de PRs
Métricas de PR pendentes

Descrição

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 encoding parameter 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 of str values 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

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Direção de pesquisa

Comece pela documentação de dbm em docs.python.org/3.13/library/dbm.html e inspecione o tratamento de CAST(? AS BLOB) no código de dbm.sqlite. Compare como os backends de dbm tratam valores str e, em seguida, atualize a documentação para explicar o comportamento da codificação e recomendar a conversão dos valores para bytes quando os chamadores precisarem de controle. Verifique o PR vinculado gh-138030 antes de começar.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
python
Domínio
documentation
Tipo de issue
Documentação
Dificuldade
3/5
Tempo estimado
1-2 dias
Status de atividade
Estagnada
Clareza
Razoavelmente clara
Facilidade para iniciantes
30/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.