Replace `float` with `float | int`
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 5.1k
- フォーク
- 2.1k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 82
説明
As discussed in python/typing#1748: I propose to (slowly) replace float with float | int and complex with complex | float | int, where applicable.
- It's more correct, even if
floatis current implicitly equivalent toint | float. - We are already prepared should the implicit promotion ever be removed.
- We give type checkers the ability to optionally disable the promotion so that type checker authors and users can experiment with it.
- Typeshed would always need to be the first step for this, so let's remove this blocker.
This issue proposes an ugly and slow, but correct and safe procedure:
- Disable flake8-pyi code Y041.
#16096 - Introduce two type aliases
FloatInt = float | intandComplexInt = complex | float | intto_typeshed.
#16068 - Globally replace all instances of
floatwithFloatIntand ofcomplexwithComplexIntin the stdlib. - After 2026-09-22 we do the same for third-party stubs.
- Review
FloatIntandComplexIntinstances are replace them with the proper types. (This will take a while.) - Remove the type aliases once they are not needed anymore (in 10 years or so ...)
Using FloatInt and ComplexInt would be disallowed for new code and the type aliases should explicitly be marked as not to be used by non-typeshed code.
We should also probably add flake8-pyi checks that checks that argument types use float | int and complex | float | int. Cases where only float/complex is allowed are probably rare.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
stdlib のスタブと _typeshed の FloatInt および ComplexInt エイリアスから始め、次に flake8-pyi の Y041 設定を確認します。stdlib 全体で float および complex のアノテーションを検索し、各候補を確認します。完了とは、計画されている stdlib 全体の移行を意味し、サードパーティ製スタブは 2026-09-22 まで保留されます。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- tooling
- issue の種類
- リファクタリング
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 静か
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100