textwrap.shorten() raises "placeholder too large" for text that already fits
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 45/100
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
- Lingua principale
- Python
- Stelle
- 77.8k
- Fork
- 37.7k
- Merge medio
- 15h 24m
- PR unite (30g)
- 728
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di python/cpython
-
What's New in 3.12 credits the unstable C API tier to PEP 697 instead of PEP 689Forse già presa Una pull request collegata a questa issue è aperta o già unita. Apertadocs
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 82/100
python/cpython#161078 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
OS-windows type-bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
docs
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
python/cpython#161007 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Null dereferencing of a pointer in initconfig.cForse già presa @lazerg l’ha presa 3 giorni fa. Apertainterpreter-core topic-C-API type-bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
python/cpython#160962 · 4 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
tests topic-profiling type-bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
python/cpython#160881 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di python/cpython
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
huggingface/smolagents#3106 ·
I maintainer di solito rispondono entro 2 giorni
-
area:scripts area:tests bug priority:later
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
Ikalus1988/MisakaNet#4358 ·
I maintainer di solito rispondono entro 1 giorno
-
Discovered ports from service discovery are never propagated to modules in Module.load()Forse già presa @vishalmore90 l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
OWASP/Nettacker#1828 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
aws-samples/sample-per-model-bedrock#708 ·
I maintainer di solito rispondono entro 1 giorno
-
maintenance
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100