python / python/typing

Annotations for `__eq__`

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

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

topic: documentation topic: typing spec
主要言語
Python
スター
1.8k
フォーク
302
平均マージ
23時間
マージ済み PR(30日)
8

説明

It would be useful to have more guidance on how __eq__ methods should be annotated.

A few considerations:

  • Enable type checkers to warn on non-overlapping equality comparisons. The type annotations should ideally allow type checkers to look at a check like A() == B() and verify whether it can ever return True.
  • Some level of support for __eq__ returning a non-boolean (classic example: numpy arrays)
  • How to think about __eq__ methods that return NotImplemented on unrecognized types versus those that throw an error

See also https://discuss.python.org/t/make-type-hints-for-eq-of-primitives-less-strict/34240

Covering this in the typing spec is important because it affects how library authors should annotate __eq__ methods in their libraries if they want all type checkers to understand these methods.

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

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

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

調査の方向性

まず typing 仕様とリンクされている discuss.python.org のスレッドを読み、eq の既存の扱いを理解してください。仕様に、重ならない比較、bool 以外の戻り値、NotImplemented、およびエラーについて合意された指針が示され、ライブラリ作者が一貫して適用できるようになれば、作業は完了です。

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

評価

技術スタック
python
領域
documentation
issue の種類
ドキュメント
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
30/100

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

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