python / python/mypy

Plugins and overloads don't interact well

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

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

bug needs discussion priority-0-high topic-overloads topic-plugins
主要言語
Python
スター
20.6k
フォーク
3.3k
PR マージ指標
PR 指標を取得中

説明

While working on our own plugin for self-checking proper types and isinstance() I have tried to use get_function_hook() to emit some additional errors for overloaded functions. However this didn't work for three reasons:

  • The hook is called for every item in the overload, not for the overload as a whole.
  • The overload logic relies on empty Messages as a sign of successful match
  • The errors emitted during overload selection are discarded afterwards, thus discarding the plugin generated errors

This issue can be fixed in three ways:

  • Calling the hook on the overload as a whole after selecting the overload variant and type checking it (this however will be a breaking API change)
  • Use newly added error codes to only abandon a variant if the error is due to bad argument type (this is however still bad because check_call() may have an accept() call possibly triggering almost arbitrary error including a nested function call with bad argument type).
  • Use a boolean attribute somewhere that will be set by check_argument_types() and will be reset after return from every accept().

I am leaning towards the last option, since it is most principled IMO.

cc @Michael0x2a

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

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

はじめの一歩

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

調査の方向性

まず、get_function_hook() をオーバーロードの選択、check_call()、check_argument_types()、accept() の流れに沿って追跡します。オーバーロードのマッチングで空の Messages がどのように使われ、プラグインのエラーがどのように破棄されるかを比較します。プラグインが生成したエラーがオーバーロードの選択を通過して保持され、有効なオーバーロードのバリアントを誤って拒否せず、選択された動作の一貫性も維持されれば完了です。

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

評価

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

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

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