Highlight differences in complex types

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

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

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
25/100
issue の種類
機能追加
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
python
領域
devtools

調査の方向性

Start with the issue's Callable example and the current incompatible-assignment diagnostic it shows. Define which typical nested-type differences should be highlighted and how multiple differences or line wrapping should behave; done means the resulting diagnostics make the differing parts clear without relying on the full, nearly identical type strings.

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

説明

diagnostics topic-error-reporting topic-usability

Sometimes it's hard to see why two types are incompatible if they are long and almost the same. Dummy example:

from typing import Callable
from mypy_extensions import Arg

x: Callable[[Arg(int, 'foobar'), Arg(int, 'bir'), Arg(int, 'fubar')], None]
y: Callable[
    [Arg(int, 'foobar'), Arg(int, 'blr'), Arg(int, 'fubar')], None]

x = y

This is the error:

t.py:7: error: Incompatible types in assignment (expression has type "Callable[[Arg(int, 'foobar'), Arg(int, 'blr'), Arg(int, 'fubar')], None]", variable has type "Callable[[Arg(int, 'foobar'), Arg(int, 'bir'), Arg(int, 'fubar')], None]")

Here's a potential better message that highlights the difference:

t.py:7: error: Incompatible types in assignment (expression has type "Callable[[Arg(int, 'foobar'), Arg(int, 'blr'), Arg(int, 'fubar')], None]", variable has type "Callable[[Arg(int, 'foobar'), Arg(int, 'bir'), Arg(int, 'fubar')], None]")
t.py:7: note: Expression type: ..., Arg(int, 'blr'), ...
t.py:7: note: Variable type:   ..., Arg(int, 'bir'), ...
t.py:7: note:                                 ^^^

It's not clear what's the best way to generalize this sort of "type diff" to arbitrary nested types and to arbitrary type differences. We should at least handle some typical cases. We could also look at how other (non-Python) language implementations handle this.

Just splitting long lines and aligning them would help a bit (but in general the alignment could be off, since there could be multiple differences in types, only some of which are problematic):

t.py:7: error: Incompatible types in assignment (expression has type "Callable[[Arg(int, 'foobar'), Arg(int, 'blr'), Arg(int, 'fubar')], None]", 
t.py:7: error:                                     variable has type "Callable[[Arg(int, 'foobar'), Arg(int, 'bir'), Arg(int, 'fubar')], None]")
主要言語
Python
スター
20.6k
フォーク
3.3k
平均マージ
1日 18時間
マージ済み PR(30日)
54

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

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

はじめの一歩

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

python/mypy のほかの issue

python/mypy の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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