Python (3.8-3.12)
1. Supported Versions & File Extensions
Section titled “1. Supported Versions & File Extensions”- Language Standard: Python 3.8 through 3.12
- Recognized Extensions:
.py,.pyi(type stubs) - Stdin Flag:
-l pythonor-l py - Measured Throughput (
v0.4.0): Peak cold repo throughput68,030 LOC/s(jinja);463.9 usFastPython BSByteString 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 (
:=) insideif,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:
HybridIndentStackhandles 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,lambdaparameters,except ... as e:bindings, andwith ... as ctx:targets rewrite to@v<depth>.<ordinal>, while:=walrus bindings inside comprehensions hoist to the enclosing function scope. - Public API Preservation (
F2): Module-leveldef/async def/classnames, parameter names, default value hashes, and return annotations stay untouched inF2. - ABI-Precise Type Contracts (
F_T):Protocoldefinitions,TypedDictshapes,typealiases, orderedTuple[A, B](TypeTuple), andUnion(A | B) /Optionalexpressions 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 inF1andF_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 inF_WCG. - Metaclass / Decorator Runtime Mutation: Decorators are hashed by name and arguments in
F1andF2; runtime class edits inside custom metaclasses are outside static scope.