textwrap.shorten() raises "placeholder too large" for text that already fits
Mantenedores costumam responder em até 1 dia
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 2/5
- Tempo estimado
- 1-3 horas
- Facilidade para iniciantes
- 45/100
Direção de pesquisa
Start by reading the textwrap implementation of _wrap_chunks() and the tests for textwrap.shorten() and wrap() with max_lines. Reproduce the supplied examples and check where the placeholder width is validated relative to truncation. Done means fitting text is returned without the placeholder error, while existing behavior for text that needs truncation remains covered by tests.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Bug description
textwrap.shorten() raises ValueError for text that fits in width when
the placeholder is wider than width:
>>> import textwrap
>>> textwrap.shorten('ab', width=4)
Traceback (most recent call last):
...
ValueError: placeholder too large for max width
shorten's docstring says such text is returned unchanged: "If it then fits
in the width, it is returned as is." 'ab' fits in width 4.
The same happens in wrap() whenever max_lines is set and the text fits but
the placeholder is wider than width:
>>> textwrap.wrap('hello world', width=20, max_lines=3, subsequent_indent=' ' * 17)
Traceback (most recent call last):
...
ValueError: placeholder too large for max width
>>> textwrap.wrap('hello world', width=20, subsequent_indent=' ' * 17)
['hello world']
_wrap_chunks() checks the placeholder-fits guard eagerly, before wrapping,
whenever max_lines is set. But the placeholder is only used when the text is
actually truncated, so the guard fires on text that never needs it.
CPython versions tested on
3.14, 3.15, CPython main branch
Operating systems tested on
macOS
Linked PRs
- gh-160044
- Linguagem predominante
- Python
- Estrelas
- 77.8k
- Forks
- 37.7k
- Merge médio
- 12h 27min
- PRs com merge (30d)
- 710
Preparar o ambiente
Inicia o contêiner de desenvolvimento do projeto no navegador, com a sua própria conta do GitHub.
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o 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.
Mais de python/cpython
-
3.16 build type-bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 62/100
python/cpython#160829 · 4 comentários ·
Mantenedores costumam responder em até 1 dia
-
dependencies infra topic-ensurepip
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 66/100
Mantenedores costumam responder em até 1 dia
-
symtable: repr() of a Symbol raises TypeError under -X lazy_imports=allTalvez já em andamento Um pull request vinculado a esta issue está aberto ou já foi mesclado. Abertastdlib topic-lazy-imports type-bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
python/cpython#160810 · 3 comentários ·
Mantenedores costumam responder em até 1 dia
-
tarfile: extractfile(member).read() of a sparse member is slow due to repeated bytes concatenationAbertaperformance stdlib triaged type-bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
python/cpython#160774 · 2 comentários ·
Mantenedores costumam responder em até 1 dia
-
tests topic-profiling type-bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
python/cpython#160334 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
Todas as issues de python/cpython
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
Graphify-Labs/graphify#4860 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
:bug: Bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 84/100
scikit-image/scikit-image#8377 ·
Mantenedores costumam responder em até 1 dia
-
Ingredient import validation accepts negative nutrient values and NaNTalvez já em andamento @LukeSekai assumiu hoje. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
wger-project/wger#2564 ·
Mantenedores costumam responder em até 2 dias
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
apache/ponymail-foal#351 ·
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 68/100
Mantenedores costumam responder em até 4 dias