finds.dev← search

// the find

yinwang0/pysonar2

★ 1,422 · Java · Apache-2.0 · updated Mar 2026

PySonar2: a semantic indexer for Python with interprocedual type inference

PySonar2 is a Java library that does whole-project interprocedural type inference for Python — the kind that correctly tracks types across function boundaries, through closures, and across control flow branches. It was built as a backend for code indexing tools (Google and Sourcegraph both used it), not as a standalone linter or IDE plugin.

The interprocedural analysis is genuinely good — it can infer return types of functions based on call sites and closures in a way that simpler tools miss. It uses CPython's own AST parser via a subprocess bridge, so the parse tree is authoritative and handles Python 2 and 3 syntax without reimplementing the grammar. The type system has union types and handles isinstance() narrowing, which most static analyzers at this level skip. The test suite uses a ref-map comparison approach (expected JSON of symbol → location bindings) that makes regressions concrete and reproducible.

Last meaningful activity appears to be several years old and the repo hasn't tracked modern Python — there's no mention of type annotations (PEP 484), dataclasses, match statements, or the typing module, which are now table stakes for any serious Python analysis tool. It's Java invoking a Python subprocess to parse ASTs, which is an awkward operational dependency: you need the right Python version on PATH and PYTHONPATH set correctly, and failures there are silent or confusing. The contributor warning ('the theory is complex and unpublished, discuss before changing') is a red flag for anyone trying to adopt or maintain it — the author is the single point of understanding. Output is a JSON dump or HTML demo, not a structured API that's easy to integrate.

View on GitHub →

// want more like this?

We dig through GitHub every week and send a few repos picked for what you actually care about — each with an honest take like this one.

Get finds in your inbox → Search again →