Same variable with a union type is not checked in "lockstep" within an expression
オープン
まだ誰も着手していません。
false-positive
feature
priority-2-low
topic-union-types
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
Test env:
- mypy 0.670
- Python 3.7.2
Test code
from typing import List, Union
def f(x: Union[int, List[int]]) -> None: # `TypeVar` can fix it
x + x
Run mypy with default option, will get
a.py:5: error: Unsupported operand types for + ("int" and "List[int]")
a.py:5: error: Unsupported operand types for + ("List[int]" and "int")
a.py:5: note: Both left and right operands are unions
But actually, both left and right operands are same variable. Only int + int or List[int] + List[int] here. It seems like mypy does not consider object identity. And I'm not sure this is a bug, because above code is meaningless.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、提供された Python 3.7 の例を mypy のデフォルトオプションで実行し、報告された union の組み合わせを issue の期待される動作と比較します。式内の繰り返されたオペランドに対する型チェックの経路を読み、その後、オブジェクトの同一性が診断に影響すべきかどうかを判断し、その動作を受け入れる場合は回帰テストのカバレッジを追加します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- compilers, devtools
- issue の種類
- バグ
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 25/100