Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

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

Abierto
#160,043 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
45/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python
Área
backend

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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
Lenguaje dominante
Python
Estrellas
77.8k
Forks
37.7k
Merge medio
12 h 14 min
PR fusionados (30 d)
729

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de python/cpython

Todos los issues de python/cpython

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.