python / python/mypy

Local type inference of numeric variables

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

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

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

説明

I have a very simple example program that produces surprising and (I think...) wrong behavior:

foo = 0

foo = 1.0

Running mypy against this file yields

test.py:3: error: Incompatible types in assignment (expression has type "float", variable has type "int")

But foo could(/should) be inferred as a float in this environment. I draw this conclusion from PEP-484

when an argument is annotated as having type float, an argument of type int is acceptable

(although this is not about function arguments per se).

I know that some improvements have been recently been made to type inference in 0.770 to use information from second (or subsequent) assignments, rather than just the first assignment. So maybe a widening from int to float could be implemented in the same way...?

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

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

はじめの一歩

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

調査の方向性

mypy を使って test.py の例で動作を再現し、次にバージョン 0.770 について参照されているローカルな型推論の変更と、関連する PEP-484 のガイダンスを調査します。int が代入された変数を後から float に拡張できるかどうかを明らかにし、その結果生じる代入動作をテストでカバーできれば完了です。

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

評価

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

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

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