Mypy is still too eager about outer context
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
Consider this example:
T = TypeVar('T')
S = TypeVar('S')
def add(x: List[T], y: List[S]) -> List[Union[T, S]]: ...
a: List[int]
b: List[str]
e: List[Union[int, str]] = add(a, b)
It fails on the last line with the following (I skip invariance notes):
error: Argument 1 to "add" has incompatible type "List[int]"; expected "List[Union[int, str]]"
error: Argument 2 to "add" has incompatible type "List[str]"; expected "List[Union[int, str]]"
If I remove the annotation for e, everything works fine.
When previously working on the external context issues, I found that I don't like how constrains for unions against unions are inferred (not that they are wrong, just counterintuitive). For example, Union[T, S] <: Union[str, int] infers T < : Union[str, int] and S <: Union[str, int], which is technically fine, but leads to errors like above.
This blocks https://github.com/python/mypy/pull/5873
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、mypy を使って注釈付きの add(a, b) の例を再現し、参照されている pull request 5873 に関する議論を読んでください。union に対する union の意図された制約推論を特定し、その後、リグレッションを導入せずに例が成功することを確認してください。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 25/100