Back to the room

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

Code Observatory / function

parse_python

codeintel.parsers.python_parser.parse_python

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

Calls (5)
SymbolFileResolved by
ParseResultbase.pythrough an import
Symbolbase.pythrough an import
_docstringpython_parser.pysame file
_Extractorpython_parser.pysame file
module_path_forpython_parser.pysame file
Called by (1)
SymbolFileResolved by
parse_file__init__.pythrough an import
Inside (1)
SymbolFileResolved by
python_parserpython_parser.pysame file
codeintel.parsers.python_parser.parse_pythonbackend/app/codeintel/parsers/python_parser.py, lines 195–225Open source
def parse_python(path: str, source: str) -> ParseResult | None:    """Parse a Python file. Returns None on a syntax error (caller falls back)."""    try:        tree = ast.parse(source, filename=path, type_comments=False)    except (SyntaxError, ValueError):        return None    module_path = module_path_for(path)    line_count = max(1, source.count("\n") + (0 if source.endswith("\n") else 1))    module = Symbol(        name=module_path.rsplit(".", 1)[-1] or path,        qualified_name=module_path,        kind="module",        start_line=1,        end_line=line_count,        signature=f"module {module_path or path}",        docstring=_docstring(tree),    )    extractor = _Extractor(module, module_path, path.endswith("__init__.py"))    for stmt in tree.body:        extractor.visit(stmt)    # De-duplicate imports, preserving order.    imports = list(dict.fromkeys(extractor.imports))    return ParseResult(        language="python",        parser="python-ast",        symbols=extractor.symbols,        imports=imports,        import_map=extractor.import_map,    )

What the index recorded

Signature
def parse_python(path: str, source: str) -> ParseResult | None:
File
backend/app/codeintel/parsers/python_parser.py
Lines
195–225
Parser
python-ast
Git blob
63495bcda67d5742151d40ab76540e513f44e088
Call sites
13 named, 5 resolved, 8 left unlinked

Read it on GitHub at this commit