Skip to content

Python (3.8-3.12)

  • Language Standard: Python 3.8 through 3.12
  • Recognized Extensions: .py, .pyi (type stubs)
  • Stdin Flag: -l python or -l py
  • Measured Throughput (v0.4.0): Peak cold repo throughput 68,030 LOC/s (jinja); 463.9 us FastPython BS ByteString SIMD lexer (Small ~85 LOC, RQ7)

2. Supported Constructs & ByteString Fast Path

Section titled “2. Supported Constructs & ByteString Fast Path”

Canontra’s pure-Haskell Python frontends (Canontra.Parser.Python and ByteString/SIMD Canontra.Parser.FastPython) parse directly into flat LinearAST arrays without intermediate concrete syntax tree allocations:

  • PEP 701 (Python 3.12): Nested f-strings with quote reuse (f"{d['k']}") and inline comments inside multi-line f-string expressions.
  • PEP 695 (Python 3.12): Type parameter syntax on functions, classes, and type aliases (type Alias[T] = ..., def fn[T, **P](x: T) -> T, class Store[K, V]: ...).
  • PEP 572: Walrus assignment expressions (:=) inside if, while, and list/dict/set/generator comprehensions, hoisting bindings cleanly into the enclosing function scope and DFG reaching definitions.
  • PEP 634: Structural pattern matching (match / case) and pattern guards.
  • Core Python Grammar: async/await, generators (yield, yield from), decorators, positional-only (/) and keyword-only (*) parameters, *args / **kwargs, try/except/finally, with / async with, and single-expression generator arguments.
  • Hybrid Indent Stack: HybridIndentStack handles arbitrary indentation depth without fixed-bitmask limits.

3. Language-Specific Alpha Scoping & F_T Rules

Section titled “3. Language-Specific Alpha Scoping & F_T Rules”
  • LEGB + Walrus Local Normalization (canonicalizeAlphaModuleForLang): Local assignments, for-loop targets, comprehension variables, lambda parameters, except ... as e: bindings, and with ... as ctx: targets rewrite to @v<depth>.<ordinal>, while := walrus bindings inside comprehensions hoist to the enclosing function scope.
  • Public API Preservation (F2): Module-level def/async def/class names, parameter names, default value hashes, and return annotations stay untouched in F2.
  • ABI-Precise Type Contracts (F_T): Protocol definitions, TypedDict shapes, type aliases, ordered Tuple[A, B] (TypeTuple), and Union (A | B) / Optional expressions flatten into sorted unions while PEP 695 type parameters normalize to α0, α1.

4. Unsupported & Conservative-Fallback Constructs

Section titled “4. Unsupported & Conservative-Fallback Constructs”
  • Dynamic Code Execution (eval, exec, compile): Preserved literally as call nodes in F1 and F_CG; dynamically built code strings are never evaluated or executed.
  • Runtime Reflection (getattr, setattr, __import__, importlib): Treated as opaque calls; dynamic attribute lookups do not invent speculative edges in F_WCG.
  • Metaclass / Decorator Runtime Mutation: Decorators are hashed by name and arguments in F1 and F2; runtime class edits inside custom metaclasses are outside static scope.