Specifying what to stub
You can give stubgen paths of the source files for which you want togenerate stubs:
- $ stubgen foo.py bar.py
This generates stubs out/foo.pyi
and out/bar.pyi
. The defaultoutput directory out
can be overridden with -o DIR
.
You can also pass directories, and stubgen will recursively searchthem for any .py
files and generate stubs for all of them:
- $ stubgen my_pkg_dir
Alternatively, you can give module or package names using the-m
or -p
options:
- $ stubgen -m foo -m bar -p my_pkg_dir
Details of the options:
-m
MODULE
,
—module
MODULE
- Generate a stub file for the given module. This flag may be repeatedmultiple times.
Stubgen will not recursively generate stubs for any submodules ofthe provided module.
-p
PACKAGE
,
—package
PACKAGE
- Generate stubs for the given package. This flag maybe repeatedmultiple times.
Stubgen will recursively generate stubs for all submodules ofthe provided package. This flag is identical to —module
apart fromthis behavior.
Note
You can’t mix paths and -m
/-p
options in the same stubgeninvocation.
Stubgen applies heuristics to avoid generating stubs for submodulesthat include tests or vendored third-party packages.