`str()` of a style from `Style.update_link()` leaves out the new link once the original has been converted to a string
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 78/100
Direzione di ricerca
Il bug si trova in rich/style.py: update_link() copia _style_definition nel nuovo Style, e __str__ restituisce quel valore in cache quando è impostato. Riproduci il problema con lo snippet presente nell'issue, poi verifica che la copia parta senza una definizione in cache, come fa _add. Il lavoro è completato quando str(style.update_link(...)) riflette il nuovo link dopo che l'originale è stato convertito in stringa, e un test copre sia l'impostazione sia la rimozione del link.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Hi! I hit this while writing generated tests against Rich. Style.update_link() returns a style with a different link, but str() of it gives the original style's definition if the original was converted to a string first:
from rich.style import Style
style = Style(bold=True)
print("before str():", str(style.update_link("http://x")))
str(style) # caches the definition on the original
print("after str():", str(style.update_link("http://x")))
Output on Rich 15.0.0 and on main (3a109cc):
before str(): bold link http://x
after str(): bold
update_link copies self._style_definition into the new style, and __str__ returns that cached string when it's set, so the copy reports the original's definition. The same happens the other way round: update_link(None) on a linked style that has been converted to a string still shows link ....
I think the copy should start with no cached definition, as _add does. I have a one-line fix with a test 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
-
HassSetVolumeRelative reports no targets (empty success list) although the volume was changedApertaintegration: media_player
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
home-assistant/core#193344 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 82/100
daniel-ospina/tortoise#13607 ·
I maintainer di solito rispondono entro 1 giorno
-
documentation priority: medium
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
I maintainer di solito rispondono entro 1 giorno
-
needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno