python / python/cpython

Other consequences of textwrap.wrap() changes in 3.15

Aperta
#140,627 11 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

stdlib type-bug
Lingua principale
Python
Stelle
77.2k
Fork
35.9k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

Bug report

Bug description:

It seems like the change in #139902 had other effects than what the PR intended. If those changes are intentional, it would be good if they were documented. And if they were not intentional, then this seem like a bug. This change has since been backported (#139902, #139903), though I don't believe those backports have been released.

Given the following code:

import textwrap
textwrap.wrap(' ABCDEFG', width=1)

In 3.14.0, this returns [' ', 'A', 'B', 'C', 'D', 'E', 'F', 'G']
In 3.15.0a1, this returns ['A', 'B', 'C', 'D', 'E', 'F', 'G']

Since the PR only mentions trailing whitespace, it appears this change was unintended.

The documentation reads as follows.

drop_whitespace
(default: True) If true, whitespace at the beginning and ending of every line (after wrapping but before indenting) is dropped. Whitespace at the beginning of the paragraph, however, is not dropped if non-whitespace follows it. If whitespace being dropped takes up an entire line, the whole line is dropped.

I am not sure how to interpret this. This line would seem to indicate the space should be preserved.

Whitespace at the beginning of the paragraph, however, is not dropped if non-whitespace follows it.

CPython versions tested on:

3.15

Operating systems tested on:

Linux

Linked PRs
  • gh-140639

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia eseguendo l'esempio textwrap.wrap(' ABCDEFG', width=1) nelle versioni di Python segnalate e leggendo il comportamento documentato di drop_whitespace. Confronta le conseguenze di issue #139902 con il PR collegato #140639; il lavoro è completato quando viene stabilito se il comportamento modificato relativo allo spazio iniziale è intenzionale e viene corretto o documentato di conseguenza.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
backend
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
30/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.