Redefinition without reassignment doesn't check existing value
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
With --allow-redefinition, mypy allows a variable to be redefined, without checking that the existing value is the correct type.
a: str = "foo"
print(a) # value needs to be used before redefinition
a: int # but it is really still str
if a > 1:
...
Expected Behaviour
In this example, mypy should detect that a is still a str, and not allow this redefinition.
It could treat the redefinition as though it is a new variable, being assigned the value of the existing one. That would result in an error like:
error: Incompatible types in assignment (expression has type "str", variable has type "int")
Or it could be a new error, like:
error: Redefinition incompatible with existing type (existing type "str", new type "int")
Actual Behaviour
mypy:
Success: no issues found in 1 source file
python:
TypeError: '>' not supported between instances of 'str' and 'int'
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、リンク先の mypy-play.net の実行例を --allow-redefinition 付きで再現し、その後、注釈付きの再定義を mypy がどのように処理しているかを追跡します。既存の str 値が後続の int 注釈と照合され、mypy が成功ではなく適切なエラーを報告するようになれば、作業は完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100