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 symbolsLoading
| Symbol | File | Resolved by |
|---|---|---|
| parse_python | python_parser.py | same file |
| Symbol | File | Resolved by |
|---|---|---|
| __init__ | python_parser.py | same file |
| _enter | python_parser.py | same file |
| _visit_func | python_parser.py | same file |
| current | python_parser.py | same file |
| visit_Attribute | python_parser.py | same file |
| visit_Call | python_parser.py | same file |
| visit_ClassDef | python_parser.py | same file |
| visit_Import | python_parser.py | same file |
| visit_ImportFrom | python_parser.py | same file |
| visit_Name | python_parser.py | same file |
| Symbol | File | Resolved by |
|---|---|---|
| python_parser | python_parser.py | same 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_funcShows 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
