`str()` of a style from `Style.update_link()` leaves out the new link once the original has been converted to a string
まだ誰も着手していません。
評価
調査の方向性
バグは 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
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
Textualize/rich のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
Textualize/rich#4269 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
Textualize/rich#4268 ·
-
Needs triage
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
Textualize/rich#4267 ·
-
難易度 1/5 1〜3時間 初心者へのやさしさ 88/100
Textualize/rich#4266 ·
-
[BUG] `Text.right_crop(0)` empties the text and an amount larger than the text makes `len()` raiseオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
Textualize/rich#4265 ·
Textualize/rich の issue をすべて見る
似ている issue
-
integration: media_player
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
home-assistant/core#193344 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
daniel-ospina/tortoise#13607 ·
メンテナーはふだん 1 日以内に返信
-
documentation priority: medium
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
メンテナーはふだん 1 日以内に返信
-
needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信