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

オープン 初心者向け
#4,262 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
cli

調査の方向性

バグは rich/style.py にあります。update_link() が _style_definition を新しい Style にコピーし、設定されている場合は __str__ がそのキャッシュ済みの値を返します。issue のスネippetで再現させ、そのうえでコピーが _add と同じくキャッシュされた定義なしで始まることを確認してください。元の style を文字列化した後でも str(style.update_link(...)) が新しいリンクを反映し、リンクの設定と解除の両方をテストが網羅していれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Python
スター
57.8k
フォーク
2.6k
平均マージ
20分
マージ済み PR(30日)
3

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Textualize/rich のほかの issue

Textualize/rich の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。