py_converter

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 23, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package py_converter lowers Python source into gIR so the taint engine in internal/analysis can analyze it, mirroring the public shape of converters/go (NewConverter / Converter.ConvertFile).

There is no Python front end reachable from Go without a new dependency, so this converter shells out to an embedded helper script (pyast.py) that parses the file with the standard library's `ast` module and prints a compact JSON tree; convertModule/convertFunction/lowerStmt/lowerExpr turn that into gIR. ConvertFile returns a clear error if python3 is not on PATH.

Known limitations:

  • A real control-flow graph IS built, via converters/ssabuild: if/while/for/ try get their own basic blocks, and PHIs are inserted on demand (Braun et al.) at the joins. A branch-free body still lowers to exactly one block, which keeps the engine's linear fast path. What remains approximate is exceptions and loop exits: lowerTry models a raise as ONE opaque edge from the try body into a single merged handler block, with no exception typing, and `break`/`continue` are dropped rather than re-routed, so a loop's exit edges are the fall-through ones only.
  • Classes are only partially modeled: methods become functions named "<Class>.<method>", but other class-body statements (class attributes, nested classes, decorators) are ignored.
  • Expression coverage spans calls, attribute/subscript reads, binary/unary and boolean operators, comprehensions, container literals, unpacking assignment, walrus (`:=`), `await`, f-strings, str.format, constants, and names. Lambdas and decorators are not specifically modeled; an unhandled expression becomes an OP_CODE_INTRINSIC "py.unsupported" and an unhandled statement is dropped, rather than aborting conversion.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsPythonFile

func IsPythonFile(path string) bool

IsPythonFile reports whether path is a Python source file this frontend lowers. Exported so internal/scan's language detection and this frontend's own file selection share ONE predicate instead of drifting copies.

Types

type Converter

type Converter struct {
	frontend.Driver[pyFileResult]
}

Converter lowers Python source files/directories into gIR: the shared frontend.Driver surface (ConvertFile/ConvertInventory/Skipped) over Python's batch hooks (see batch). Requires python3 on PATH.

func NewConverter

func NewConverter() *Converter

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL