StubConfig¶
- class StubConfig(execution_mode: ExecutionMode = ExecutionMode.RUNTIME, include_private: bool = False, respect_all: bool = True, verbose: bool = False, strict: bool = False, union_style: str = 'modern', alias_style: str = 'compatible', include_docstrings: bool = False, exclude: list[str] = <factory>, output_dir: str | None = None, infer_types_from_docstrings: bool = False, incremental_update: bool = False)[source]¶
Bases:
objectPer-run configuration options for stub generation.
All fields have sensible defaults so callers need not supply any arguments for standard usage.
- Parameters:
execution_mode (ExecutionMode) – Defaults to
RUNTIME.include_private (bool) – When
True, symbols whose names start with_are included. Defaults toFalse.respect_all (bool) – When
Trueand__all__is present, only names in__all__are stubbed. Defaults toTrue.verbose (bool) – When
True, INFO-level diagnostics are printed. Defaults toFalse.strict (bool) – When
True, any ERROR diagnostic causes a non-zero exit. Defaults toFalse.union_style (str) – Output style for union annotations.
"modern"emits PEP 604X | Ysyntax (e.g.str | None);"legacy"emitsOptional[X]/Union[X, Y]. Defaults to"modern".include_docstrings (bool) – When
True, copy the docstring from each function, method, and class into the generated stub as a literal string body instead of.... Useful when a stub doubles as quick-reference documentation without requiring the original source. Defaults toFalse.alias_style (str) –
Output format for type alias declarations.
"compatible"(default) — always emitName: TypeAlias = <rhs>using theTypeAliasannotation fromtyping. Works on all Python 3.10+ versions."pep695"— emit the Python 3.12+type Name = <rhs>soft-keyword form (PEP 695). Only use this when your project targets Python 3.12+."auto"— usepep695when running on Python 3.12+, otherwise fall back tocompatible.
exclude (list of str) – Glob patterns (relative to the package root) for files to skip during package processing. Only used by
generate_package(). Defaults to[].output_dir (str or None) – Default output directory for package processing.
Nonemeans stubs are written alongside the source files. Defaults toNone.infer_types_from_docstrings (bool) – When
True, attempt to infer parameter and return types from NumPy, Google, or Sphinx-style docstrings for functions and methods that lack explicit annotations. Inferred types are emitted as inline# type:comments rather than live annotations, making their origin clearly visible. Defaults toFalse.incremental_update (bool) – When
True, wrap the generated stub in# stubpy: auto-generated begin/endmarkers and merge it into any existing.pyifile, preserving content outside the markers. WhenFalse(default) the.pyiis overwritten completely.
- execution_mode: ExecutionMode = 'runtime'¶
- __init__(execution_mode: ExecutionMode = ExecutionMode.RUNTIME, include_private: bool = False, respect_all: bool = True, verbose: bool = False, strict: bool = False, union_style: str = 'modern', alias_style: str = 'compatible', include_docstrings: bool = False, exclude: list[str] = <factory>, output_dir: str | None = None, infer_types_from_docstrings: bool = False, incremental_update: bool = False) None¶
See also
Public API reference — overview of all public names.