Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

feature: Support covariance for Control lists (use Sequence/Mapping or Mutable ones)

オープン
#6,574 コメント 5 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

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

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
55/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
静か
技術スタック
python
領域
frontend

調査の方向性

まず、controls パラメーターが list[Control] として型付けされている Flet のコンテナーコンストラクター(Column、Row、View、TabBarView を含む)を特定します。これらのパラメーターがどのように宣言およびテストされているかを確認し、関連する型ヒントを更新して共変なシーケンスを受け入れられるようにしてから、Control のサブクラスのリストが実行時の動作を弱めることなく型チェックを通過することを検証します。

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

説明

feature request
Duplicate Check
Describe the requested feature

Currently, many Flet containers (like Column, Row, View, etc.) define their controls property strictly as list[Control]. Because Python's list is invariant, this causes significant issues when building custom structured UI architectures.

Suggest a solution

Change the type hinting for controls in constructors from list[Control] to a covariant alternative, like typing.Sequence[Control]. This allows passing lists of subclasses (e.g., list[MyCustomControl]) without breaking type safety or triggering linter warnings (e.g., Pylance(reportArgumentType)

Screenshots

No response

Additional details

I've ran into this problem writing my own Tabs class wrapper that coordinates specific child components.

class InertiaListViewResponsibleTabs(ft.Tabs):
    def __init__(
        self,
        tab_bar: EmphasisTabBar, # My own TabBar wrapper
        view_controls: list[ft.Control],
        ...
    ):
        super().__init__(
            on_change=self._on_change,
            ...,
            content=ft.Column(
                ...,
                controls=[tab_bar, ft.TabBarView(controls=view_controls)],
            ),
        )

The bad workaround I am forced to use:
To bypass this, I have to lower my type safety, accept any Control, and then manually pollute my runtime code with isinstance checks to filter out unexpected controls:

def __init__(
    self,
    ...,
    view_controls: list[ft.Control],
    ...
):
    super().__init__(...)

    # Runtime overhead and boilerplate just because of invariant list hints
    self._inertia_list_view_mask = [isinstance(control, InertiaListView) for control in view_controls]

    self._view_controls = view_controls

def _on_change(self, e: ft.Event[ft.Tabs]):
    if self._inertia_list_view_mask[e.control.selected_index]:
        # Cast is a bad tone
        list_view = cast(
            InertiaListView, self._view_controls[e.control.selected_index]
        )
        list_view.scroll_to(list_view.current_offset)

If ft.TabBarView accepted Sequence[Control], Python's type checkers would naturally allow writing:

def __init__(
    self,
    tab_bar: EmphasisTabBar,
    view_controls: list[InertiaListView],
    ...
):
    super().__init__(
        on_change=self._on_change,
        ...,
        content=ft.Column(
            ...,
            # Assignment without Pylance[reportArgumentType]
            controls=[tab_bar, ft.TabBarView(controls=view_controls)],
        ),
    )

This simplifies _on_change logic:

def _on_change(self, e: ft.Event[ft.Tabs]):
    list_view = self._view_controls[e.control.selected_index]
    list_view.scroll_to(list_view.current_offset)
主要言語
Python
スター
17.4k
フォーク
737
平均マージ
1日 8時間
マージ済み PR(30日)
46

環境構築

はじめの一歩

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

flet-dev/flet のほかの issue

flet-dev/flet の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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