Commit 9dd1252
committed
Replace runtime-type quotation with splice-into-source typechecking
Type-check LLM-generated Callables by splicing them into the Template's real
module source -- in place at the template def's position -- and running mypy on
the whole module, raising only on diagnostics inside the spliced region. This
removes the brittle quotation layer (type_to_ast, signature_to_ast, collect_*,
_RenameTransformer) and the runtime/local-type stubbing it depended on, which
mishandled common types such as Enum and runtime-created Pydantic models.
- mypy_type_check now takes (generated, anchor); the anchor (Template.__default__)
is provided by the type_check_anchor effect op, bound per call by
Template.__apply__ (so nested synthesis sees the right one) and rebound to None
around tool-argument decoding, so the argument path skips the check.
- Region-scoped diagnostics: unrelated pre-existing errors elsewhere in the module
never block synthesis (no spurious retry burn).
- Leaves the template def's decorators untouched (mypy checks the body against its
declared return type regardless of decorators); explicit pre-scan for non-nestable
constructs (star-import, __future__); source recovery via getsourcelines/file/
linecache (REPL-defined templates); fatal mypy errors are surfaced not swallowed.
- Name collisions (#542) are handled structurally by nesting/shadowing, so the
AST-rename pass is deleted.
- Delete the quotation emitters + their unit tests; add behavior tests covering
collision shadowing, the gate, closures, method/static/class templates,
Enum/dataclass context, injected-name, non-nestable, and linecache recovery.1 parent 72bb624 commit 9dd1252
5 files changed
Lines changed: 523 additions & 2000 deletions
File tree
- effectful/handlers/llm
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
| 33 | + | |
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| |||
430 | 430 | | |
431 | 431 | | |
432 | 432 | | |
433 | | - | |
434 | | - | |
435 | | - | |
436 | | - | |
437 | | - | |
438 | | - | |
439 | | - | |
440 | | - | |
441 | | - | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
442 | 445 | | |
443 | 446 | | |
444 | 447 | | |
| |||
672 | 675 | | |
673 | 676 | | |
674 | 677 | | |
675 | | - | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
676 | 687 | | |
677 | 688 | | |
678 | 689 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
551 | 551 | | |
552 | 552 | | |
553 | 553 | | |
554 | | - | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
555 | 561 | | |
556 | 562 | | |
557 | 563 | | |
| |||
0 commit comments