3

変数の型を伝えることで PyDev コード補完を支援する方法はありますか?

PDT では、PHPDoc のような構文をそのような目的で使用できます。

/* @var $my_var MyClass */
$my_var = myFunction();
// PDT is able to figure out that $my_var is a MyClass object.

しかし、今のところ、Python で同じことを行う方法がわかりません。

4

3 に答える 3

3

Actually, you can if you do an assert isinstance()

E.g.:

a = function()
assert isinstance(a, MyClass)
a. <- would get the proper completions

Note that Pydev does analyze the return of the functions, so, it's possible that it knows that on a number of cases.

Also, that shouldn't have runtime penalties if you use python -O (which will remove the asserts)

于 2010-01-14T19:25:28.563 に答える
1

いいえ(ドキュメントを参照)。PyDev は、インポートされたものと言語キーワードの補完を行うようです。

ただ、これはあまり出てこないようです。問題の変数は、デフォルト値のない関数引数として渡された場合にのみ pydev に認識されないようです。また、独自のクラスで動作する関数がある場合、それはクラス メンバー (そのため、オートコンプリートは既に機能しています)。

于 2010-01-06T22:30:55.317 に答える