python / python/typeshed

Inconsistent dataclass declaration

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

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

主要言語
Python
スター
5.1k
フォーク
2.1k
平均マージ
1日 19時間
マージ済み PR(30日)
82

説明

The dataclass decorator in the typeshed package has an inconsistency in its overloads. Specifically, when cls is passed explicitly as None, it is unclear whether additional arguments (e.g., init, repr, etc.) should be allowed or not. The current implementation allows passing cls=None alongside additional arguments, but this usage is not explicitly documented or validated.

Expected Behavior

The overloads should clearly define and document the behavior of cls=None when additional arguments are provided:

If allowed, the typing should reflect that explicitly.
If not allowed, the implementation should prevent or warn against such usage.

Current Behavior

Passing cls=None with arguments like kw_only=True is allowed, but this behavior is not described in the overloads. For example:

decorator = dataclass(None, kw_only=True)
@decorator
class MyClass:
    x: int

The above works but is ambiguous in terms of type checking and intended usage.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

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

調査の方向性

まず、typeshed パッケージ内の dataclass デコレーターのオーバーロードを見つけ、示されている dataclass(None, kw_only=True) の例と比較します。追加の引数を伴う cls=None がサポートされているかを明確にし、そのうえでオーバーロードとドキュメントがその判断を一貫して表すようにします。型チェッカーとユーザーにとって動作が明確になれば完了です。

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

評価

技術スタック
python
領域
devtools
issue の種類
バグ
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
35/100

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

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