python / python/mypy

More ideas about plugin system

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

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

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

説明

After some time spent on writing SQLAlchemy plugin and a discussion with @JukkaL here are some comments and ideas about our plugin :

  • Currently, member signature hook is not called on __init__ and __new__. Current workaround is to use function hook, but it is still painful. The solution would require moving type_object_type() (and maybe a bunch of other helpers) from checkmember.py to a separate module (which is probably a good idea on its own). We can also move some helpers from checker.py related to type objects to the same module.

  • During semantic analysis types of expressions are not known. This poses a problem in attrs and even more in SQLAlchemy: When generating an __init__ method for a model, plugin needs to figure out what is a type of attributes from definitions like name = Column(String(40)). Currently I do this using some heuristics that works in 95% of cases (and so does attrs plugin), but a better solution is probably to just store names of "magic" classes (SQLAlchemy models, dataclasses etc.) in the plugin state, add a dummy __init__ to symbol table, and defer figuring out actual type to the method signature hook that is called in type checking (depends on fixing previous bullet).

  • It is better to move calling semantic analysis hooks to the very end, or (probably even better) just allow them to defer current target (but this is currently not possible).

  • We should not allow most type operations in semantic analysis hooks (we can't enforce it, but should at least document it clearly). Some operations are still OK (like map_instance_to_supertype() or erase_type()).

  • The type checking hooks should also be able to defer current target using a special return value or an exception (e.g. __init__ signature hook in the SQLAlchemy example above if one would use a user-defined type in an import cycle).

Probably, most (or all) of decisions should be made after the upcoming semanal.py refactoring.

(Also function hook is inconvenient, but @gvanrossum already mentioned this in https://github.com/python/mypy/issues/5409 that has a bunch of good ideas about improving plugin system.)

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

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

はじめの一歩

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

調査の方向性

まず checkmember.py と checker.py のプラグイン関連ロジックを読み、次に予定されている semanal.py のリファクタリングと、リンクされている issue #5409 を確認してください。この issue には、意味解析および型チェックのフックに関する設計上の質問がいくつか挙げられていますが、単一の変更や具体的な完了基準は定義されていません。

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

評価

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

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

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