SymbolTable¶
- class SymbolTable[source]¶
Bases:
objectOrdered collection of
StubSymbolentries for one module.Preserves source-definition order so that the emitted stub mirrors the original file layout. Provides lookup by name and iteration by kind.
Examples
>>> tbl = SymbolTable() >>> tbl.add(ClassSymbol(name="Foo", lineno=1)) >>> tbl.add(FunctionSymbol(name="bar", lineno=10)) >>> len(tbl) 2 >>> tbl.get("Foo").kind <SymbolKind.CLASS: 'class'> >>> "Foo" in tbl True >>> "Missing" in tbl False
- add(symbol: StubSymbol) None[source]¶
Append symbol to the table.
If a symbol with the same name already exists it is overwritten in the index (the old entry is retained in the ordered list for compatibility, but lookup returns the newer entry).
- get(name: str) StubSymbol | None[source]¶
Return the symbol for name, or
Noneif not present.
- get_class(name: str) ClassSymbol | None[source]¶
Return the
ClassSymbolfor name, orNone.
- get_function(name: str) FunctionSymbol | None[source]¶
Return the
FunctionSymbolfor name, orNone.
- by_kind(kind: SymbolKind) Iterator[StubSymbol][source]¶
Yield all symbols of kind in definition order.
- classes() Iterator[ClassSymbol][source]¶
Yield all
ClassSymbolentries in source order.
- functions() Iterator[FunctionSymbol][source]¶
Yield all top-level
FunctionSymbolentries in source order.
- variables() Iterator[VariableSymbol][source]¶
Yield all
VariableSymbolentries in source order.
- aliases() Iterator[AliasSymbol][source]¶
Yield all
AliasSymbolentries in source order.
- overload_groups() Iterator[OverloadGroup][source]¶
Yield all
OverloadGroupentries in source order.
- sorted_by_line() list[StubSymbol][source]¶
Return all symbols sorted by lineno ascending.
See also
Public API reference — overview of all public names.