`Table(min_width=...)` raises `AssertionError: Sum of ratios must be > 0` on a very narrow console
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 72/100
Direzione di ricerca
Il problema si trova in Table._calculate_column_widths in rich/table.py, dove ratio_distribute viene chiamata con larghezze di colonna che sommano 0 quando min_width supera lo spazio disponibile. Inizia riproducendo con lo snippet dell'issue alle larghezze 1 e 2, poi verifica se il padding dovrebbe essere saltato quando nessuna colonna ha larghezza. Il lavoro è completo quando la tabella viene renderizzata a quelle larghezze con min_width impostato e un test copre anche il caso del Panel stretto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Hi! I hit this while writing generated tests against Rich. Printing a table that has a min_width raises AssertionError when the console is so narrow that the columns get no width at all:
from rich.console import Console
from rich.table import Table
for width in (1, 2, 3, 10):
console = Console(width=width, color_system=None)
try:
console.print(Table("a", min_width=5))
print(f"width {width}: rendered")
except Exception as error:
print(f"width {width}: {type(error).__name__}: {error}")
Output on Rich 15.0.0 and on main (3a109cc), with the tables themselves left out:
width 1: AssertionError: Sum of ratios must be > 0
width 2: AssertionError: Sum of ratios must be > 0
width 3: rendered
width 10: rendered
Without min_width, the same table renders at widths 1 and 2 (cut down to its borders), and so does expand=True.
In Table._calculate_column_widths, every column width is 0 at these sizes, and the table is still narrower than min_width, so it pads the columns with ratio_distribute(_max_width - table_width, widths). The ratios are the widths, which sum to 0, and ratio_distribute asserts they don't.
It can also happen inside a narrow container: console.print(Panel(Table("a", min_width=5), width=5)) on a 40-column console raises the same error. I'd expect it to render like the table without min_width does. I have a small fix that skips the padding when no column has any width, and I'm happy to open a PR.
Python 3.13, macOS.
- Lingua principale
- Python
- Stelle
- 57.8k
- Fork
- 2.6k
- Merge medio
- 20m
- PR unite (30g)
- 3
Preparare l'ambiente
- 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 Textualize/rich
-
Color.parse() raises raw ValueError instead of ColorParseError for an empty rgb(...) componentAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
Textualize/rich#4269 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
Textualize/rich#4268 ·
-
Needs triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
Textualize/rich#4267 ·
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 88/100
Textualize/rich#4266 ·
-
[BUG] `Text.right_crop(0)` empties the text and an amount larger than the text makes `len()` raiseAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
Textualize/rich#4265 ·
Tutte le issue di Textualize/rich
Issue simili
-
Internal ErrorApertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
frappe/frappe_docker#2071 ·
I maintainer di solito rispondono entro 1 giorno
-
bug python
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
traceloop/openllmetry#4717 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
The-Pocket/PocketFlow#161 ·
-
[Bug]: Webapp workspace fails to render in Safari — "Can't find variable: requestIdleCallback"Apertacomp/desktop P2 type/bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
NousResearch/hermes-agent#157702 ·
I maintainer di solito rispondono entro 1 giorno
-
scibench_physics / scibench_chemistry: a correct answer scores 0 when the unit has a power of tenForse già presa @BahaaMattar l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
EvolvingLMMs-Lab/lmms-eval#1699 ·
I maintainer di solito rispondono entro 1 giorno