build_symbol_table¶
- build_symbol_table(module: ModuleType | None, module_name: str, ast_symbols: ASTSymbols, all_exports: set[str] | None = None, include_private: bool = False) SymbolTable[source]¶
Build a
SymbolTableby merging runtime and AST information.Live objects from module are matched against the
ASTSymbolsby name and combined into typedStubSymbolentries. When module isNone(AST-only mode), alllive_*fields areNone.The symbol table is populated in this order:
TypeAlias / TypeVar declarations (from AST).
Classes — merged with
inspect.getmemberswhen module is available; filtered to symbols whose__module__matches module_name.Module-level functions — from AST;
live_funcset from module.Overload groups — grouped
@overloadfunctions from AST.Module-level variables — from AST;
live_valueset from module.
- Parameters:
module (types.ModuleType or None) – Loaded module from
load_module(), orNonefor AST-only mode.module_name (str) – Synthetic
_stubpy_target_*module name used to filter local classes from imported ones.ast_symbols (ASTSymbols) – Output from
ast_harvest().all_exports (set of str or None) – When provided, only names in this set are included.
Nonemeans include all public (non-underscore-prefixed) names unless include_private isTrue.include_private (bool) – When
True, names starting with_are not filtered out. Defaults toFalse.
- Returns:
SymbolTable – Populated, source-order-preserving symbol table.
Examples
>>> import types as _t >>> from stubpy.ast_pass import ast_harvest >>> m = _t.ModuleType("_stubpy_target_ex") >>> class Foo: pass >>> Foo.__module__ = "_stubpy_target_ex" >>> m.Foo = Foo >>> syms = ast_harvest("class Foo: pass") >>> tbl = build_symbol_table(m, "_stubpy_target_ex", syms) >>> tbl.get("Foo").kind.value 'class'
See also
Public API reference — overview of all public names.