Back to the room

Pass 3 of 3 · Deep dive of PHAROSPass 1 · OverviewPass 2 · How it works

Code Observatory / class

_Extractor

codeintel.parsers.python_parser._Extractor

PINNED SOURCE Source and edges from the index at this commit. An execution appears only where one was recorded.

PHAROS at 975a38dMIT license

Around this symbol

Search all symbols

Loading

Called by (1)
SymbolFileResolved by
parse_pythonpython_parser.pysame file
Contains (10)
SymbolFileResolved by
__init__python_parser.pysame file
_enterpython_parser.pysame file
_visit_funcpython_parser.pysame file
currentpython_parser.pysame file
visit_Attributepython_parser.pysame file
visit_Callpython_parser.pysame file
visit_ClassDefpython_parser.pysame file
visit_Importpython_parser.pysame file
visit_ImportFrompython_parser.pysame file
visit_Namepython_parser.pysame file
Inside (1)
SymbolFileResolved by
python_parserpython_parser.pysame file
codeintel.parsers.python_parser._Extractorbackend/app/codeintel/parsers/python_parser.py, lines 94–153Open source
class _Extractor(ast.NodeVisitor):    def __init__(self, module_symbol: Symbol, module_path: str, is_package: bool) -> None:        self.module_path = module_path        self.is_package = is_package        self.symbols: list[Symbol] = [module_symbol]        self.stack: list[Symbol] = [module_symbol]        self.imports: list[str] = []        self.import_map: dict[str, str] = {}    @property    def current(self) -> Symbol:        return self.stack[-1]    # ── definitions ────────────────────────────────────────────────────    def _enter(self, node: ast.AST, kind: str) -> None:        parent = self.current        name = node.name  # type: ignore[attr-defined]        sym = Symbol(            name=name,            qualified_name=f"{parent.qualified_name}.{name}" if parent.qualified_name else name,            kind=kind,            start_line=_start_line(node),            end_line=getattr(node, "end_lineno", None) or node.lineno,  # type: ignore[attr-defined]            signature=_signature(node),            docstring=_docstring(node),            parent=parent.qualified_name,        )        self.symbols.append(sym)        self.stack.append(sym)        for deco in getattr(node, "decorator_list", []):            self.visit(deco)        if isinstance(node, ast.ClassDef):            for base in node.bases:                self.visit(base)        else:            for arg in ast.walk(node.args):  # type: ignore[attr-defined]                if isinstance(arg, ast.arg):                    sym.add_identifier(arg.arg)        for child in node.body:  # type: ignore[attr-defined]            self.visit(child)        self.stack.pop()    def visit_ClassDef(self, node: ast.ClassDef) -> None:        if self.current.kind in ("function", "method"):            # Classes defined inside functions are part of that function.            self.generic_visit(node)            return        self._enter(node, "class")    def _visit_func(self, node: ast.FunctionDef | ast.AsyncFunctionDef) -> None:        if self.current.kind in ("function", "method"):            # Closures belong to the enclosing function's chunk.            self.current.add_identifier(node.name)            self.generic_visit(node)            return        self._enter(node, "method" if self.current.kind == "class" else "function")    visit_FunctionDef = _visit_func    visit_AsyncFunctionDef = _visit_func

Shows the first 60 of 99 lines. The rest is on GitHub at this commit.

What the index recorded

Signature
class _Extractor(ast.NodeVisitor):
File
backend/app/codeintel/parsers/python_parser.py
Lines
94–192
Parser
python-ast
Git blob
63495bcda67d5742151d40ab76540e513f44e088

Read it on GitHub at this commit