Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

textwrap.shorten() raises "placeholder too large" for text that already fits

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

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
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
python
Domínio
backend

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

stdlib type-bug
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

Abrir no Codespaces

Inicia o contêiner de desenvolvimento do projeto no navegador, com a sua própria conta do GitHub.

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.

Mais de python/cpython

Todas as issues de python/cpython

Issues semelhantes

Mais issues de Python

Receba novas issues na sua caixa de entrada

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