python / python/mypy

Any is excessively used as outer context for inference

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

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

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

説明

Consider this example:

from typing import Any
  
def foo(**kwargs: Any) -> None: ...

foo(bar=reveal_type([1])) # Revealed type is List[Any]

Such behavior causes many false negatives for plugins that provide precise type checking for various ORMs, this includes SQLAlchemy plugin, our internal plugins, and likely Django plugin.

My guess this was added so that an empty list in Any context is inferred as List[Any] instead of List[<nothing>], but I think this is counterproductive. If empty collections cause issues for plugins they can easily work around using private APIs to re-infer argument type in generated precise context (for example using has_uninhabited_component() and ctx.api.accept()). Or maybe we can provide public API for inference.

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

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

はじめの一歩

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

調査の方向性

mypy で例を再現し、**kwargs: Any の呼び出しにおいて外側の Any コンテキストが reveal_type([1]) にどのような影響を与えるかを調査します。issue で言及されているプラグインの再推論 API(has_uninhabited_component()ctx.api.accept() を含む)を確認します。完了条件は、一貫した推論動作または公開 API について合意し、それを実装することです。例と影響を受けるプラグインシナリオに対するリグレッションカバレッジも含みます。

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

評価

技術スタック
python
領域
compilers, devtools
issue の種類
バグ
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
25/100

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

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