Wrong type annotations for read only mapping types.

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

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

@RasmusNygren がすでに取り組んでいます。

2026年5月6日 から。

  • #2245 @RasmusNygren による — オープン

評価

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

調査の方向性

src/confluent_kafka/admin/init.py の issue に示されている conf 引数の周辺から始め、次に Dict でアノテーションされた他の読み取り専用 mapping 引数を検索します。該当するアノテーションを collections.abc.Mapping に置き換え、dict[str, str] 構成が型チェッカーに受け入れられることを確認します。

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

説明

status:under-review

There are type annotations that uses Dict to annotate read-only mapping arguments, e.g. the conf argument here: https://github.com/confluentinc/confluent-kafka-python/blob/7d0abd551c5061e655fbf403f9baa09af040e29b/src/confluent_kafka/admin/__init__.py#L118

The problem is that Dict is invariant in its value type, meaning that in the example above where conf is typed as conf: Dict[str, Union[str, int, float, bool] it is not valid to assign a dict of type Dict[str, str].

That means code like this

from confluent_kafka.admin import AdminClient
conf = {
    "bootstrap.servers": "kafka:9092"),
} # inferred type dict[str, str]
admin_client = AdminClient(conf)

is rejected by type-checkers.

The solution here would be to annotate conf with collections.abc.Mapping instead of Dict, as Mapping is covariant in its value-type.

主要言語
Python
スター
528
フォーク
977
平均マージ
2日 19時間
マージ済み PR(30日)
19

環境構築

  • Dockerfile・Docker Compose ファイルなし
  • プルリクエストのテンプレートあり
  • コントリビューションガイドなし

はじめの一歩

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

confluentinc/confluent-kafka-python のほかの issue

confluentinc/confluent-kafka-python の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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