python / python/mypy

Deal better with "def __init__(self)" return type

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

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

needs discussion priority-1-normal topic-usability
主要言語
Python
スター
20.6k
フォーク
3.3k
PR マージ指標
PR 指標を取得中

説明

If untyped defs are disallowed, mypy requires that def __init__(self): has an explicit -> None return type, even though normally the return type is optional for __init__. This can be surprising, so it would be better for mypy to produce a special note in this case about why the return type is required even for __init__.

Another idea would be to drop the error message if using --check-untyped-defs, since the explicit return type arguably doesn't add much value.

See #5943 for context.

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

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

はじめの一歩

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

調査の方向性

まず、型指定のない init メソッドについて mypy が戻り値の型の欠落をどのように報告するか、また --check-untyped-defs がその診断にどのような影響を与えるかを追跡します。意図された動作が特別な説明用注記を表示することなのか、エラーを抑制することなのかを明確にし、選択した動作を回帰テストのカバレッジで検証します。

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

評価

技術スタック
python
領域
devtools
issue の種類
機能追加
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
35/100

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

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