Specifying how to generate stubs

By default stubgen will try to import the target modules and packages.This allows stubgen to use runtime introspection to generate stubs for Cextension modules and to improve the quality of the generatedstubs. By default, stubgen will also use mypy to perform light-weightsemantic analysis of any Python modules. Use the following flags toalter the default behavior:

  • —no-import
  • Don’t try to import modules. Instead only use mypy’s normal search mechanism to findsources. This does not support C extension modules. This flag also disablesruntime introspection functionality, which mypy uses to find the value ofall. As result the set of exported imported names in stubs may beincomplete. This flag is generally only useful when importing a module causesunwanted side effects, such as the running of tests. Stubgen tries to skip testmodules even without this option, but this does not always work.
  • —parse-only
  • Don’t perform semantic analysis of source files. This may generateworse stubs – in particular, some module, class, and function aliases maybe represented as variables with the Any type. This is generally onlyuseful if semantic analysis causes a critical mypy error.
  • —doc-dir PATH
  • Try to infer better signatures by parsing .rst documentation in PATH.This may result in better stubs, but currently it only works for C extensionmodules.