`DataTable.RowLabelSelected.__rich_repr__` raises `AttributeError` when the row has no label
まだ誰も着手していません。
評価
調査の方向性
クラッシュは textual/widgets/_data_table.py 内の DataTable.RowLabelSelected の __rich_repr__ で発生しており、約676行目で self.label.plain を呼び出しています。_on_click を確認してください。これは row.label を渡しており、ラベルのない行では None になります。issue の再現手順を実行したうえで、pretty_repr(event) が例外を出さずに label=None を出力すること、そして label の型注釈が Text | None を許容していることを確認してください。
索引モデルが issue の本文から書いたものです。
説明
Hi! I hit this while writing generated tests against Textual's widgets. In a table where some rows have labels, clicking the label cell of a row added without one posts RowLabelSelected with label=None, and the message's repr raises.
from rich.pretty import pretty_repr
from textual.app import App, ComposeResult
from textual.widgets import DataTable
class RowLabelApp(App):
def compose(self) -> ComposeResult:
yield DataTable()
def on_mount(self) -> None:
table = self.query_one(DataTable)
table.add_column("A")
table.add_row("x", label="one")
table.add_row("y") # no label
def on_data_table_row_label_selected(self, event: DataTable.RowLabelSelected) -> None:
print("message:", pretty_repr(event))
if __name__ == "__main__":
RowLabelApp().run() # then click the label cell of the second row
Expected: RowLabelSelected(row_key=..., row_index=1, label=None).
Actual (on Textual 8.2.7, and main at 5e5b7ef):
File "textual/widgets/_data_table.py", line 676, in __rich_repr__
yield "label", self.label.plain
AttributeError: 'NoneType' object has no attribute 'plain'
label is annotated as Text, but _on_click passes row.label, which is None for an unlabelled row. I think the same repr is used when messages are logged to textual console, though I've only checked it directly.
I'd suggest yielding None for a missing label and widening the annotation to Text | None. I'm happy to send a PR.
- 主要言語
- Python
- スター
- 37.7k
- フォーク
- 1.5k
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
Textualize/textual のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
Textualize/textual#6790 · コメント 2 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 80/100
Textualize/textual#6789 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
Textualize/textual#6787 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
Textualize/textual#6782 · コメント 1 件 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
Textualize/textual#6778 · コメント 1 件 ·
Textualize/textual の issue をすべて見る
似ている issue
-
Console writes URL credentials to the local log, though AGENTS.md says secrets never reach diskオープン
難易度 1/5 1時間未満 初心者へのやさしさ 86/100
sandbox-quantum/switch#2163 ·
メンテナーはふだん 1 日以内に返信
-
bug pydanty:is-working
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
pydantic/pydantic-ai#13939 ·
メンテナーはふだん 1 日以内に返信
-
priority: low python
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
LearningCircuit/local-deep-research#8849 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 86/100
francescopace/espectre#223 ·
メンテナーはふだん 3 日以内に返信
-
good first issue Status: Triaged
難易度 1/5 1時間未満 初心者へのやさしさ 84/100
canonical/imagecraft#538 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信