python / python/typing

Typing spec should be clearer that type checkers are not expected to support PEP 3141

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

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

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

説明

With regards to the numeric tower, PEP 484 states:

PEP 3141 defines Python’s numeric tower, and the stdlib module numbers implements the corresponding ABCs (Number, Complex, Real, Rational and Integral). There are some issues with these ABCs, but the built-in concrete numeric classes complex, float and int are ubiquitous (especially the latter two :-).

Rather than requiring that users write import numbers and then use numbers.Float etc., this PEP proposes a straightforward shortcut that is almost as effective: when an argument is annotated as having type float, an argument of type int is acceptable; similar, for an argument annotated as having type complex, arguments of type float or int are acceptable. This does not handle classes implementing the corresponding ABCs or the fractions.Fraction class, but we believe those use cases are exceedingly rare.

This is a very useful passage to link to, because:

  • It clearly (albeit tersely) states that the PEP-3141 ABCs are problematic
  • It clearly states the separate solution that PEP-484 proposes for dealing with numeric types
  • It frames the PEP-484 solution in opposition and contrast to the PEP-3141 solution

The parallel passage in the typing spec currently states this:

Python’s numeric types complex, float and int are not subtypes of each other, but to support common use cases, the type system contains a straightforward shortcut: when an argument is annotated as having type float, an argument of type int is acceptable; similar, for an argument annotated as having type complex, arguments of type float or int are acceptable.

Since PEP-484 is a historical document rather than a piece of living documentation, it would be great if the typing spec could state as clearly as PEP-484 that the PEP-3141 ABCs are not the recommended way of annotating numeric types in Python, and that type checkers may not necessarily (and in fact probably won't ever) support them.

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

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

はじめの一歩

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

調査の方向性

typing spec の「Special cases for float and complex」ページから始め、リンクされている PEP 484 と PEP 3141 の該当箇所とその文言を比較してください。PEP 3141 の ABCs は推奨される数値アノテーションではなく、type checker がサポートしていない場合があることを明確にしてください。更新後の記述では、既存の数値ショートカットの説明を維持してください。

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

評価

技術スタック
python
領域
documentation
issue の種類
ドキュメント
難易度
2/5
見積もり時間
1〜3時間
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
38/100

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

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