textwrap.shorten() raises "placeholder too large" for text that already fits
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
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
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
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de python/cpython
-
tests topic-profiling type-bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
python/cpython#160881 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
3.16 build pending type-bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
python/cpython#160829 · 5 comentarios ·
Los mantenedores suelen responder en 1 día
-
dependencies infra topic-ensurepip
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
Los mantenedores suelen responder en 1 día
-
symtable: repr() of a Symbol raises TypeError under -X lazy_imports=allPosiblemente ocupada @anistark la tomó hoy. Abiertostdlib topic-lazy-imports type-bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
python/cpython#160810 · 4 comentarios ·
Los mantenedores suelen responder en 1 día
-
tarfile: extractfile(member).read() of a sparse member is slow due to repeated bytes concatenationPosiblemente ocupada @devdavidejesus la tomó hoy. Abiertoperformance stdlib triaged type-bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
python/cpython#160774 · 2 comentarios · 1 asignado ·
Los mantenedores suelen responder en 1 día
Todos los issues de python/cpython
Issues similares
-
changelog investigate
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100
ramnes/notion-sdk-py#433 ·
-
docs pkg:core
Dificultad 1/5 Menos de una hora Aptitud para principiantes 84/100
pydantic/pydantic-ai#11929 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
intake/intake-esm#789 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
MemMachine/MemMachine#1877 ·
Los mantenedores suelen responder en 3 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
openedx/openedx-authz#579 ·
Los mantenedores suelen responder en 1 día