3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

pybind11 モジュールに mypy 用型アノテーションをつけるメモ

Posted at

pybind11 で作った native module にも mypy 型アノテーション(stub 情報)つけたい.
自前で書いてもいいけどめんどいよね...

こちらで自動でいけました!

つかう

pybind11 を使ってビルドした native module mymodule.cpython-38-x86_64-linux-gnu.so などがあるとします.

PYTHONPATH=. pybind11-stubgen mymodule --no-setup-py --root-module-suffix="" --ignore-invalid=all --output-dir="./generated"

という感じでいけます!

カレントディレクトリの .so は検索してくれない(pybind11-stubgen が内部で呼んでいる importlib.import_module)ので, .so を直接読んで stub つくりたいときは PYTHONPATH 環境設定あたりでパスを通しておきましょう!
(そうしないと ModuleNotFoundError がでる)

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?