`str()` of a style from `Style.update_link()` leaves out the new link once the original has been converted to a string

Abierto Apto para principiantes
#4,262 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
78/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python
Área
cli

Línea de trabajo

El error está en rich/style.py: update_link() copia _style_definition en el nuevo Style, y __str__ devuelve ese valor en caché cuando está establecido. Reproduce el problema con el fragmento del issue y luego comprueba que la copia empiece sin definición en caché, como lo hace _add. Está terminado cuando str(style.update_link(...)) refleja el nuevo enlace después de que el original se haya convertido a cadena, y una prueba cubre tanto establecer como borrar el enlace.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Python
Estrellas
57.8k
Forks
2.6k
Merge medio
20 min
PR fusionados (30 d)
3

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de Textualize/rich

Todos los issues de Textualize/rich

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.