/** * Python code emitter — Declaration IR → Python source code. * * Replaces `file.py.njk` + `_macros.njk` (~619 lines of Nunjucks templates) * with a typed TypeScript function that walks the FileDecl tree. * * The emitter produces correctly-formatted Python 3.11+ code using modern * `X | None` union syntax. Output should be byte-identical to the template * output after ruff+black formatting. * * Structural blocks emitted (in order): * 1. Header comment (auto-generated warning) * 2. Imports (abc, dataclasses/pydantic, typing, context, local types) * 3. For each type in the file: * a. @dataclass or BaseModel class definition with docstring * b. _shorthand_property ClassVar * c. Field declarations with type annotations + defaults * d. load() static method * e. Collection helpers (load_X / save_X) * f. Polymorphic dispatch (load_) * g. save() instance method * h. to_yaml() and to_json() methods * i. Factory classmethods * j. Method stubs (as comments) */ import { FileDecl } from "../../ir/declarations.js"; import { ExprVisitor } from "../../ir/visitor.js"; /** * Render the cancellation-token import line for a `@runtimeCancellable` file. * * `path` is a dotted `module.symbol` reference. Absolute paths (no leading dot) * are emitted unchanged. Relative paths (leading dots) are written relative to * the model output root, so the leading-dot count is scaled by the file's group * depth — mirroring `relativePythonImport` — to resolve correctly from any * subfolder. */ export declare function pythonCancellationTokenImport(path: string, group?: string): string; /** * Emit a complete Python file from a FileDecl. */ export interface PythonEmitterOptions { cancellationTokenPath?: string; nativeSerialization?: "none" | "pydantic"; } export declare function emitPythonFile(decl: FileDecl, visitor: ExprVisitor, group?: string, options?: PythonEmitterOptions): string;