DataTable column added with the default `None` is at least four cells wide, though its cells are empty

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

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

評価

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

調査の方向性

DataTable のメソッド _get_row_renderables と _update_column_widths、および Issue で言及されている update_cell(..., update_width=True) の経路を読んでください。列サイズ調整に関する既存の DataTable テストを確認し、None セルのテストを追加してください。測定された幅が空セルの描画と一致し、報告されたテーブル幅が修正されていれば完了です。

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

説明

Hi! I hit this while writing generated tests against Textual's widgets. add_column on a table that already has rows fills those rows with default, which is None. The cells are drawn empty, but the column is sized as if they contained the text None.

import asyncio

from textual.app import App, ComposeResult
from textual.widgets import DataTable

class NewColumnApp(App):
    def compose(self) -> ComposeResult:
        yield DataTable()

    def on_mount(self) -> None:
        table = self.query_one(DataTable)
        table.add_column("A")
        table.add_row("1")
        table.add_column("B")  # existing rows get the default, None

async def main():
    async with NewColumnApp().run_test() as pilot:
        await pilot.pause()
        table = pilot.app.query_one(DataTable)
        for column in table.ordered_columns:
            print(f"column {column.label.plain}: content_width={column.content_width}")
        print("cell B:", repr(table.get_cell_at((0, 1))))
        print("table width:", table.virtual_size.width)

asyncio.run(main())

Output on Textual 8.2.7 (and the same on main at 5e5b7ef):

column A: content_width=1
column B: content_width=4
cell B: None
table width: 9

I'd expect column B to be 1 wide (its label), and the table 6 wide.

_get_row_renderables draws a None cell as empty text, but _update_column_widths measures default_cell_formatter(None), which is str(None). update_cell(..., None, update_width=True) goes through the same path.

I'd suggest measuring None cells as empty in _update_column_widths, to match how they're drawn. I'm happy to send a PR.

主要言語
Python
スター
37.7k
フォーク
1.5k
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

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

Textualize/textual のほかの issue

Textualize/textual の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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