Forbid shlex.quote returning a quoted empty string (`”””`) for falsey non-`str` data
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- Python
- Estrelas
- 77.2k
- Forks
- 36k
- Métricas de merge de PRs
- Métricas de PR pendentes
Descrição
Bug report
Bug description:
Full discussion and history of the bug is on discuss.python.org.
tldr:
shlex.quote's opening check for the empty string as a special case is still placed before the isinstance type check. This is intentional as when the isinstance check was added, the patch was intended to not break compatibility with eg people expecting shlex.quote(None) to return "''", implicitly coercing None to the empty string "" and then quoting it as "''".
def quote(s):
if not s:
return "''"
if not isinstance(s, str):
raise TypeError(f"expected string object, got {type(s).__name__!r}")
...
We think either of the following is a best course of action:
- Print a
DeprecationWarningwhen one callsquoteon falsey non-strdata - Leave the function alone, as people may now be relying on this as a feature, not a bug, and we don't gain much by doing a patch.
Or we could do a hard-break and just swap the order of the isinstance and if not s checks around, which would break anybody relying on None -> "''" (not recommended!).
I have a couple of git tags that I will link below with reference implementation for 'fixing' this issue (if it needs to be fixed). I just need the gh- number of this issue first for the blurb entries.
CPython versions tested on:
CPython main branch
Operating systems tested on:
No response
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Direção de pesquisa
Leia as verificações atuais de string vazia e tipo de shlex.quote e, em seguida, revise a discussão vinculada e o histórico de compatibilidade. A issue ainda não está pronta para uma implementação concreta: os maintainers precisam escolher entre emitir um aviso, preservar o comportamento ou introduzir uma quebra incompatível antes que seja possível definir a conclusão.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- python
- Domínio
- cli
- Tipo de issue
- Bug
- Dificuldade
- 5/5
- Tempo estimado
- Mais de uma semana
- Status de atividade
- Pouca atividade
- Clareza
- Precisa de esclarecimento
- Facilidade para iniciantes
- 25/100