MontyRepl: support external functions via snapshot/resume pattern
## Summary
`MontyRepl.feed()` doesn't support external function calls. When a REPL session is created with `external_functions` declared, calling any external function from `feed()` raises:
```
MontyRuntimeError: NotImplementedError: External function 'fetch' not implemented with standard execution
```
## Current Behavior
The iterative `start()`/`resume()` pattern works on `Monty` for external functions, and `MontyRepl` works for pure Python state persistence — but the two don't compose.
```python
import pydantic_monty
def my_fetch(url: str) -> str:
return f"Hello, {url}!"`
repl, output = pydantic_monty.MontyRepl.create(
'x = 10',
external_functions=['my_fetch'],
)
repl.feed('x') # works — returns 10
repl.feed('result = my_fetch("https://example.com")')
# MontyRuntimeError: NotImplementedError: External function 'my_fetch' not implemented with standard execution
```
## Expected Behavior
`feed()` should support external function calls, allowing the caller to resolve them (via snapshots, callbacks, or whatever mechanism fits the REPL API) and have the results persist in REPL state alongside regular variables and functions.
```python
repl = pydantic_monty.MontyRepl(external_functions=['my_fetch'])
repl.feed('x = 10') # pure Python — returns 10
# Some mechanism to resolve external calls during feed():
result = repl.feed('data = my_fetch("https://example.com")')
# ... resolve the external call ...
repl.feed('len(data)') # both x and data persist in REPL state
```
## Environment
- pydantic-monty 0.0.7
- Python 3.13
- macOS
关闭于 2026-03-03 1 条评论