`reveal_type` should print out nice formatted types
オープン
まだ誰も着手していません。
priority-1-normal
topic-reveal-type
topic-tests
topic-usability
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
Extracted from #6460
Say you have
lx: Optional[Tuple[str, int]] = None
lx[0]
reveal_type(lx)
mypy outputs
Value of type "Optional[Tuple[str, int]]" is not indexable
Revealed type is 'Union[Tuple[builtins.str, builtins.int], None]'
As you can see (and probably know) it shows two different representations for the inferred type. For user ergonomics the revealed type should be 'Optional[Tuple[int, str]]' as well, no?
The maybe too naive but works for me change is
@@ -1051,7 +1051,7 @@ class MessageBuilder:
self.fail('Invalid signature "{}" for "{}"'.format(func_type, method_name), context)
def reveal_type(self, typ: Type, context: Context) -> None:
- self.fail('Revealed type is \'{}\''.format(typ), context)
+ self.fail('Revealed type is {}'.format(self.format(typ)), context)
def reveal_locals(self, type_map: Dict[str, Optional[Type]], context: Context) -> None:
# To ensure that the output is predictable on Python < 3.6,
But then you get 1.000.000 failures which is expected because the tests rely on the verbose output.
E.g.
Expected:
main:10: error: Revealed type is 'builtins.int' (diff)
main:11: error: Revealed type is 'Tuple[builtins.int, builtins.int]' (diff)
main:13: error: Revealed type is 'Literal[1]' (diff)
main:14: error: Argument 1 to "force2" has incompatible type "Tuple[int, in...
main:14: error: Revealed type is 'Tuple[builtins.int, builtins.int]' (diff)
Actual:
main:10: error: Revealed type is "int" (diff)
main:11: error: Revealed type is "Tuple[int, int]" (diff)
main:13: error: Revealed type is "Literal[1]" (diff)
main:14: error: Argument 1 to "force2" has incompatible type "Tuple[int, in...
main:14: error: Revealed type is "Tuple[int, int]" (diff)
This makes it a non-trivial change.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
MessageBuilder.reveal_type から始めます。ここでは issue に現在の出力構築が示されているので、既存のフォーマット済みの型出力と比較してください。テストスイート全体で影響を受ける reveal_type の期待値を更新し、reveal された型がユーザー向けのフォーマットを使用するようにしてから、mypy テストを実行して更新された診断を確認してください。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- devtools
- issue の種類
- 機能追加
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100