StubContext¶
- class StubContext(alias_registry: list[AliasEntry] = <factory>, type_module_imports: dict[str, str]=<factory>, used_type_imports: dict[str, str]=<factory>, config: StubConfig = <factory>, diagnostics: DiagnosticCollector = <factory>, symbol_table: Any | None = None, all_exports: set[str] | None = None, module_namespace: dict[str, ~typing.Any]=<factory>)[source]¶
Bases:
objectMutable state container scoped to one stub-generation run.
Create one instance per
generate_stub()call, or pass a pre-configured instance to supply custom options.- alias_registry¶
Registered type aliases from imported sub-modules.
- Type:
list of AliasEntry
- config¶
Per-run options (execution mode, privacy, verbosity, etc.).
- Type:
- diagnostics¶
Accumulated warnings and errors from the pipeline.
- Type:
- symbol_table¶
Populated after the symbol-table stage;
Noneuntil then.- Type:
SymbolTable or None
- module_namespace¶
The full
__dict__of the loaded module, populated after stage 1 (module loading). Used byresolve_function_params()to look up forwarding-target callables by name. Empty in AST-only mode.- Type:
Examples
>>> ctx = StubContext() >>> ctx.diagnostics.summary() '0 errors, 0 warnings, 0 infos' >>> ctx.config.execution_mode.value 'runtime' >>> ctx.symbol_table is None True
- alias_registry: list[AliasEntry]¶
- config: StubConfig¶
- diagnostics: DiagnosticCollector¶
- lookup_alias(annotation: Any) str | None[source]¶
Return the alias string for annotation if registered, else
None.Examples
>>> ctx = StubContext() >>> ctx.alias_registry.append(AliasEntry(str | int, "types.T")) >>> ctx.type_module_imports["types"] = "from pkg import types" >>> ctx.lookup_alias(str | int) 'types.T' >>> ctx.lookup_alias(str | float) is None True
- __init__(alias_registry: list[AliasEntry] = <factory>, type_module_imports: dict[str, str]=<factory>, used_type_imports: dict[str, str]=<factory>, config: StubConfig = <factory>, diagnostics: DiagnosticCollector = <factory>, symbol_table: Any | None = None, all_exports: set[str] | None = None, module_namespace: dict[str, ~typing.Any]=<factory>) None¶
See also
Public API reference — overview of all public names.