SymbolTable

class SymbolTable[source]

Bases: object

Ordered collection of StubSymbol entries 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
__init__() None[source]
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 None if not present.

get_class(name: str) ClassSymbol | None[source]

Return the ClassSymbol for name, or None.

get_function(name: str) FunctionSymbol | None[source]

Return the FunctionSymbol for name, or None.

by_kind(kind: SymbolKind) Iterator[StubSymbol][source]

Yield all symbols of kind in definition order.

classes() Iterator[ClassSymbol][source]

Yield all ClassSymbol entries in source order.

functions() Iterator[FunctionSymbol][source]

Yield all top-level FunctionSymbol entries in source order.

variables() Iterator[VariableSymbol][source]

Yield all VariableSymbol entries in source order.

aliases() Iterator[AliasSymbol][source]

Yield all AliasSymbol entries in source order.

overload_groups() Iterator[OverloadGroup][source]

Yield all OverloadGroup entries in source order.

all_names() list[str][source]

Return all symbol names in definition order.

sorted_by_line() list[StubSymbol][source]

Return all symbols sorted by lineno ascending.

See also

Public API reference — overview of all public names.