python / python/mypy

Plugin api named_type() is ambiguous and inconsistent and broken

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

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

priority-1-normal refactoring topic-plugins
主要言語
Python
スター
20.6k
フォーク
3.3k
PR マージ指標
PR 指標を取得中

説明

The plugin API defines two different interfaces (TypeAnalyzerPluginInterface and SemanticAnalyzerPluginInterface) that each define a method named_type(). These look almost identical, but looks are deceptive.

First, the specified signatures differ subtly:

  • The second argument to SemanticAnalyzerPluginInterface.named_type() is optional, while for TypeAnalyzerPluginInterface.named_type() is is mandatory.
  • Also the first argument name differs (qualified_name vs. plain name).

Second, the implementations differ:

  • The semantic analyzer (in semanal.py) starts the lookup in the local namespace, then globals, then builtins.
  • The type checker (in checker.py) has two different strategies: if there's no dot in the name, it starts in globals, then builtins; but if there's a dot, it starts in the table of modules (i.e. the current scope doesn't enter into it).

Third, the type checker's named_type() implementation doesn't actually take a list of type arguments at all -- it's a method with only one argument, the name to look up. It always fills in all type parameters with Any. (It looks like the method we want here is named_generic_type().)

Fourth, apparently mypy's own type checking doesn't catch the discrepancy between the implemented spec (only a name) and the interface spec (name + args).

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

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

はじめの一歩

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

調査の方向性

まず、TypeAnalyzerPluginInterface.named_type() と SemanticAnalyzerPluginInterface.named_type() を、semanal.py と checker.py の実装と比較します。named_generic_type() と型チェックの設定を調べ、シグネチャの不一致が検出されない理由を理解します。プラグインのインターフェースと実装で一貫した合意済みの API が定義され、不一致が型チェックまたはテストによってカバーされれば完了です。

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

評価

技術スタック
python
領域
compilers
issue の種類
リファクタリング
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
25/100

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

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